sealearner
[求助]jsp+javabean 提示NullPointerException
java文件中用main主函数调用下面的成员函数,可以输出结果
jsp中用javabean调用确提示java.lang.NullPointerException,这个错误网上是说有对象的值为null导致的,
大家帮忙找找小弟错那了,先谢谢大家了!
代码:
public StringBuffer getBybr(){
bybrselect=new StringBuffer();
int rowcount=0;
try{
con=(new DbConnect()).getConn();//发现是这里的有问题
pstmt=con.prepareStatement("select * from hyls where
tl_date=? and br=?");
pstmt.setString(1,tl_date);
pstmt.setString(2,br);
rs=pstmt.executeQuery();
bybrselect.append("<div style='WIDTH: 100%; HEIGHT: 250;
BACKGROUND-COLOR: transparent; OVERFLOW: scroll;'>");
bybrselect.append("<table border=1 width=500 cellSpacing=0
cellPadding=0>");
while(rs.next()){
rowcount++;
br=rs.getString("br");
ac_no=rs.getString("ac_no");
amount=rs.getString("amount");
tl_date=rs.getString("tl_date");
bybrselect.append("<tr>");
bybrselect.append("<td width=50><font
size=2>"+br+"</font></td>");
bybrselect.append("<td width=200><font
size=2>"+ac_no+"</font></td>");
bybrselect.append("<td width=100><font
size=2>"+amount+"</font></td>");
bybrselect.append("<td width=100><font
size=2>"+tl_date+"</font></td>");
bybrselect.append("</tr>");
}
bybrselect.append("</table>");
bybrselect.append("</div>");
if(rowcount==0){
bybrselect.append("没有发生");
}
rs.close();
pstmt.close();
con.close();
}
catch(SQLException e){
e.printStackTrace();
}
return bybrselect;
}
jsp文件:
<body>
<jsp:useBean id="findBean" class="com.test.Test" scope="page" />
<% String br=request.getParameter("br");
String tl_date=request.getParameter("tl_date");
findBean.setBr(br);
findBean.setTldate(tl_date);
out.println(findBean.getBr());//都能输出值
out.println(findBean.getTldate());
%>
<%=br%>
<%=tl_date%>
<% StringBuffer temp=findBean.getBybr(); %>
[[i] 本帖最后由 sealearner 于 2008-5-20 15:38 编辑 [/i]]