Klaus: jsp opbject abfüllen probleme

Beitrag lesen

tach ich habe 2 jsps und 3 beans das erste jsp ruft das zweite auf. das zweite ruft die funktion getdata auf, bekommt das object data gefüllt und sollte es dan ausgeben, aber es funktioniert nicht...

index.jsp:

<html> <head> <title>  :: Lehrmittel-Suche </title> <link rel="STYLESHEET" href="css/tss.css" type="text/css"> </head> <body>

<table border="0" width="100%" height="100%" cellspacing="0" cellpadding="0" align="center">     <tr>       <td width="100%" valign="top" align="center" height="100%">         <form action="suchergebnisse.jsp" method="post">         <table border="0" width="600" cellspacing="1">           <tr>             <td width="100%" colspan="4"><font face="Arial" size="2"> </font></td>           </tr>           <tr>             <td width="600" bgcolor="#FF0066" align="center" colspan="4"><b><font color="#FFFFFF" size="2" face="Arial">Lehrmittel-Suche</font></b></td>           </tr>           <tr>             <td width="600" colspan="4"><font face="Arial" size="2"> <img border="0" src="pic/TSSnet_Contents-Pfeil.gif"><a href="hilfe.html">Hilfe</a><br><br>               </font></td>           </tr>           <tr>             <td width="9"></td>             <td width="191"><font face="Arial" size="2">ISBN-Nummer:</font></td>             <td width="200"><font face="Arial" size="2"><input type="text" name="txtISBN" size="20" style="border: 1 solid #FF0080"></font></td>             <td width="200"></td>           </tr>           <tr>             <td width="9"></td>             <td width="191"><font face="Arial" size="2">Titel:</font></td>             <td width="200"><font face="Arial" size="2"><input type="text" name="txtTitel" size="20" style="border: 1 solid #FF0080"></font></td>             <td width="200"></td>           </tr>           <tr>             <td width="9"></td>             <td width="191"><font face="Arial" size="2">Beschreibung:</font></td>             <td width="200"><font face="Arial" size="2"><input type="text" name="txtBeschreibung" size="20" style="border: 1 solid #FF0080"></font></td>             <td width="200"></td>           </tr>           <tr>             <td width="9"></td>             <td width="191"><font face="Arial" size="2">Autor:</font></td>             <td width="200"><font face="Arial" size="2"><input type="text" name="txtAutor" size="20" style="border: 1 solid #FF0080"></font></td>             <td width="200"></td>           </tr>           <tr>             <td width="9"></td>             <td width="191"><font face="Arial" size="2">Medium</font></td>             <td width="200"><select size="1" name="ddmMedium" style="border: 1 solid #FF0080">                 <option value="Buch">Buch</option>                 <option value="CD">CD</option>                 <option value="Dokumentation">Dokumentation</option>                 <option value="Diskette">Diskette</option>                 <option value="Heft">Heft</option>                 <option selected value=""></option>               </select></td>             <td width="200"></td>           </tr>           <tr>             <td width="9"></td>             <td width="191"></td>             <td width="200"><br>               <input type="submit" value="suchen" name="B1" style="background-color: #FFFFFF; border: 1 solid #FF0066">               <input type="reset" value=" reset " name="B2" style="background-color: #FFFFFF; border: 1 solid #FF0066"></td>             <td width="200"></td>           </tr>         </table>         </form>       </td>     </tr>   </table> </body> </html>

schergebnisse.jsp:

<html> <head> <title> suchergebnisse </title> </head>

<jsp:useBean id="index" scope="session" class="lehrmittel.indexBean" /> <jsp:useBean id="db" scope="session" class="lehrmittel.DB" />

<body> <% Object[][] data = {}; data = db.getdata(0);

data = index.aufbereitung(data); out.println(data[0][0].toString()); %>

<%           out.println("Autor" + request.getParameter("txtAutor")); request.getParameter("txtISBN"); request.getParameter("txtTitel");     request.getParameter("ddmMedium");     request.getParameter("txtBeschreibung"); %> </body> </html>

indexBean.java:

package lehrmittel;

import java.io.*;

public class indexBean implements Serializable {   public DB Database = new DB();   Object[][] data = {};

private void writeObject(ObjectOutputStream oos) throws IOException {     oos.defaultWriteObject();   }   private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {     ois.defaultReadObject();   }

public Object[][] aufbereitung(Object[][] data){     if(data.length > 0)     {       for(int i = 0; i < data[0].length; i++)       {         if(data[0][i] == null)           data[0][i] = "";       }     }     return data;     }

}

SQL.java:

package lehrmittel; public class SQL {   public DB Database = new DB();   private final String[] SQLList  = new String[9];   private String   Temp_SQL = "";

public SQL() {

SQLList[0] = "select * from art;";    // SQLList[0] = "SELECT Lehrmittel.ISBN, art.art FROM art INNER JOIN ON art.art_nr ";     //SQLList[0] += "= Lehrmittel.art_nr WHERE art.art = " + "'Buch'";     //Suche nach ISBN & Medium

SQLList[1] = "SELECT Lehrmittel.Titel, art.art FROM art INNER JOIN Lehrmittel ON ";     SQLList[1] += "art.art_nr = Lehrmittel.art_nr WHERE Lehrmittel.Titel= " + "'Test'" + " AND art.art = " + "'Buch'";     //Suche nach Titel & Medium

SQLList[2] = "SELECT Lehrmittel.Autor, Lehrmittel.Titel, art.art FROM art INNER JOIN ";     SQLList[2] += "Lehrmittel ON art.art_nr = Lehrmittel.art_nr WHERE ";     SQLList[2] += "art.art = " + "'Buch'" + " AND Lehrmittel.Autor = " + "'Test'" + " AND Lehrmittel.Titel = " + "'Test'";     //Suche nach Titel & Autor & Medium

SQLList[3] = "SELECT Lehrmittel.Autor, art.art FROM art INNER JOIN Lehrmittel ON ";     SQLList[3] += "art.art_nr = Lehrmittel.art_nr WHERE Lehrmittel.Autor = " + "'Test'" + " AND art.art = " + "'Buch'";     //Suche nach Autor & Medium

SQLList[4] = "SELECT Lehrmittel.Beschreibung. art.art FROM art INNER JOIN Lehrmittel ";     SQLList[4] += "ON art.art_nr = Lehrmittel.art_nr WHERE Lehrmittel.Beschreibung = ";     SQLList[4] += "'Test'" + " AND art.art = " + "'Buch'";     //Suche nach Beschreibung & Medium

}

public String GetSQL(){     return Temp_SQL;   }

public void SetSQL(int SQL_Nr)   {     Temp_SQL = SQLList[SQL_Nr];   }

}

db.java:

package lehrmittel;

import java.sql.*;

public class DB {   private SQL SQLList = new SQL();   private Connection con;   private Statement stmt;   private ResultSet res;

//Standardkonstruktor   public DB()   {

}

public Object[][] getdata(int SQL_Nr) throws Exception   {     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");     con = DriverManager.getConnection("jdbc:odbc:Lehrmittel");     stmt = con.createStatement(res.TYPE_SCROLL_INSENSITIVE , res.CONCUR_READ_ONLY);

//SetSQL()     SQLList.SetSQL(SQL_Nr);

//GetSQL()     res = stmt.executeQuery(SQLList.GetSQL());

int _rows = 0,         _cols = 0;

switch(SQL_Nr)     {       case 0:       case 1:       case 3:       case 4:         _cols= 3;//2         break;

case 2:         _cols = 4;//3         break;       //Hier entsprechende Erweiterungen implementieren     }

res.last();     _rows = res.getRow();     res.beforeFirst();

Object[][] RecordSet = new Object[_rows][_cols];

_rows = 0;

String[] _Temp = new String[_cols];

while(res.next())     {       for(int loop=0; loop < _cols; loop++)       _Temp[loop] = res.getString(loop+1);

Object[] Record = new Object[_cols];

for(int loop=0; loop < _cols; loop++)       Record[loop] = _Temp[loop];

RecordSet[_rows++] = Record;     }

res.close();     stmt.close();     con.close();

return RecordSet;

}

}