问题描述
web网页在运行一段时间后就出现HTTPStatus500错误,重新启动Tomcat后又正常。出现信息:typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperExceptionorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rootcausejava.lang.NullPointerExceptionorg.apache.jsp.ProManage.ProRKShow_jsp._jspService(org.apache.jsp.ProManage.ProRKShow_jsp:114)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/5.5.9logs.数据库连接池:xml设置:<Contextpath=""docbase="ROOT"debug="0"reloadable="true"removeAbandoned="true"removeAbandonedTimeout="60"><Resourcename="jdbc/mingri"type="javax.sql.DataSource"auth="Container"driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=store"username="sa"password=""maxActive="5000"maxIdle="10"maxWait="-1"/></Context>数据库连接类publicclassDBResult{publicstaticConnectionconn=null;static{try{Contextctx=newInitialContext();ctx=(Context)ctx.lookup("java:comp/env");DataSourceds=(DataSource)ctx.lookup("jdbc/mingri");try{conn=ds.getConnection();}catch(SQLExceptione){e.printStackTrace();}}catch(NamingExceptione){e.printStackTrace();}}publicResultSetgetResult(Stringsql){try{Statementstmt=conn.createStatement();ResultSetrs=stmt.executeQuery(sql);returnrs;}catch(Exceptione){}returnnull;}publicvoiddoExecute(Stringsql){try{Statementstmt=conn.createStatement();stmt.executeQuery(sql);}catch(Exceptione){}}publicPreparedStatementgetPreparedStatement(Stringsql){try{PreparedStatementpstmt=conn.prepareStatement(sql);returnpstmt;}catch(Exceptione){}returnnull;}}在jsp页面中调用ResultSet之后也有运行close();
解决方案
解决方案二:
java.lang.NullPointerException空指针是不是你的Connection用了没有关,池子里没有了?
解决方案三:
曾经在每次调用后写过conn.close(),直接就断开了连接,什么页面都连接不了了。
解决方案四:
修改了程序,每次使用后关闭connection,HTTPStatus500空指针的问题到不会再出现了,变成运行一段时间后,客户端无法显示网页,是不是和服务器有关啊?引用1楼csouyangjun的回复:
java.lang.NullPointerException空指针是不是你的Connection用了没有关,池子里没有了?
解决方案五:
LS的,报的是404找不到网页错误吗?
解决方案六:
顶一楼,调试的时候最好不要直接关闭tomcat服务器,很多时候都是Connection没有关闭!最终报500,俺有N次啦!
解决方案七:
500错误一半是后台错误,楼主可用调试跟踪,就能发现问题所在