Nullpointerexception thrown when webpage kept open for long time
I'm developing a website using JSP and Servlets using Apache - tomcat 5.5 as server. My application runs fine. But whenever I leave any webpage open and return back to it after some time say 30minutes, and click on any button or icon, it throws error sayin -
Sep 16, 2011 2:11:33 PM org.apache.catalina.core.Standard开发者_如何转开发WrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.homepage_jsp._jspService(homepage_jsp.java:107)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
Sounds like your session is timing out. You need to either force the user to login again, or extend your session timeout.
You can change the session timeout by editing your web.xml and adding:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
Which will give you a session timeout of 60 minutes. -1 means there is no timeout.
java.lang.NullPointerException at org.apache.jsp.homepage_jsp._jspService(homepage_jsp.java:107)
The symptom that this only occurs after a long time indeed indicates that the session has been timed out. But changing the session timeout is not the right solution. You have actually a bug in your JSP.
Because you're using old fashioned JSP scriptlets <% %>
instead of normal Java classes such as servlets to control the request/response and do the business stuff in the JSP, it's harder to naildown the root cause of the NullPointerException
. You need to open the generated homepage_jsp.java
in server's work directory and head to line 107 and finally trackback this line into your homepage.jsp
so that you can fix the bug.
Perhaps you need to do a request.getSession()
instead of request.getSession(false)
, or you need to check if a session attribute is not null
before accessing it, etcetera.
精彩评论