javabean与jsp的传值
我写了类,在类内或类间调用一个函数有返回直,但在jsp中调用同一个函数就返回空直
这是什么原因啊,怎么解决,谢谢
package sqlBean;
import java.sql.*;
public class topicBean{
Connection con=null;
ResultSet rs = null;
public topicBean() throws
InstantiationException,
IllegalAccessException,
ClassNotFoundException,
SQLException{
try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
} catch (Class
NotFoundException e)
{
System.out.println(e.toString());
}
}
public ResultSet getResult(String sql){
rs = null;
try {
con = DriverManager.getConnection( "jdbc:odbc:web ");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs =stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
/* public static void main(String at[]) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
topicBean cdb = new topicBean();
ResultSet rs = cdb.getResult( "select * from topic ");
try {
while(rs.next()){
System.out.println(cdb.rs.getString( "topic_name ")+ " ");
}
} catch (SQLException e) {
System.out.println( "2 ");
e.printStackTrace();
}
} */
}
jsp中的调用:
String sql = "select * from topic ";
ResultSet rs = topicbean.getResult(sql);
rs 在页面中有
NullPointerException <jsp:useBean id= "topicbean " scope= "session " class= "sqlBean.topicBean " />
topicbean的申明
------解决方案--------------------。。 没看出来。。
------解决方案--------------------好呀,我试,你把这“ResultSet rs = topicbean.getResult(sql); ”改为ResultSet rs = request.topicbean.getResult(sql); 看一下行不?不然就把“ <jsp:useBean id= "topicbean " scope= "session " class= "sqlBean.topicBean " /> ”改为 <jsp:useBean id= "topicbean " scope= "request " class= "sqlBean.topicBean " /> 看看。