多次刷新JSP页面,就会显示java.lang.NullPointerException

多次刷新JSP页面,就会显示java.lang.NullPointerException

各位:请教问题如下:
我调用一个javabean:package File.Databeans;
import java.sql.*;
public class webNewsBean{
    String newstype;
StringBuffer queryResult;
Connection con;
public webNewsBean(){
queryResult=new StringBuffer();
}
public void setnewstype(String s){
newstype=s.trim();
queryResult=new StringBuffer();
}
public String getnewstype(){
return newstype;
}
public void setConnection(Connection con){
              this.con=con;
}
    public StringBuffer getQueryResult(){
   
  try{
  Statement sql;
  ResultSet rs;
  queryResult.append(" <table border=0 align=left>");
 
  sql=con.createStatement();
  DatabaseMetaData metadata=con.getMetaData();
  rs=sql.executeQuery("select * from system_news where News_type='"+newstype+"'order by System_ID desc");
  int i=0;
  while(rs.next()){
  i++;
  queryResult.append(" <tr>");
  queryResult.append(" <td>● </td> <td> <a href=newsviews.jsp?System_ID="+rs.getString(1)+">"+rs.getString("News_Title")+" </a> </td>");
  queryResult.append(" </tr>");
  if(i==8){break;}
  }
  queryResult.append(" </table>");

  }catch(SQLException e){
      queryResult.append("新闻类型不能为空"+e);
  }
  return queryResult;
}


}


在JSP页面中是这样调用的,
<%Connection connection=conSet.getOneConnection();
    webNewsBean.setConnection(connection);

String newstype="systemnews";
    %>
            <jsp:setProperty name="webNewsBean" property="newstype" value=" <%=(String)newstype%>"/>           
  <%=webNewsBean.getQueryResult()%>
当我访问这个JSP页面是时,开始是可以正常访问的,经过多次刷新页面后就会报如下错误:
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NullPointerException
File.Databeans.webNewsBean.getQueryResult(webNewsBean.java:27)
org.apache.jsp.Index_jsp._jspService(Index_jsp.java:215)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
UP
Connection con;
Statement sql;
  ResultSet rs;
这类的东西在用完之后都要调用close()!!!

不调用的话,连接不释放,资源很快就会被耗光,就没法再访问了!
up
up
友情up
友情up