0
我在Linux服務器上託管了一個網站。如上所述,在服務器上,我在日誌文件中收到錯誤消息。handeling JSP會話中的問題
現在我的問題是如何處理Linux服務器上的會話,因爲在所有頁面上它只考慮Session == null
,不知道爲什麼。
對於下面一行:if (sessionUID.equals(rs1.getString("userid")))
Stacktrace:] with root cause java.lang.NullPointerException
at org.apache.jsp.iframehomemiddle_jsp._jspService(iframehomemiddle_jsp.java:544)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
這是怎麼了,我從Servlet的發送會話到JSP:
if (rs1.next()) {
HttpSession session = request.getSession();
session.setAttribute("USERID", rs1.getString("userid"));
request.getRequestDispatcher("HomePage.jsp").include(request, response);
}
這就是我如何在JSP中處理會話:
<%
response.setHeader("Cache-Control", "no-cache"); //Forces caches to obtain a new copy of the page from the origin server
response.setHeader("Cache-Control", "no-store"); //Directs caches not to store the page under any circumstance
response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
response.setHeader("Pragma", "no-cache"); //HTTP 1.0 backward compatibility
String sessionUID = (String) session.getAttribute("USERID");
if (null == sessionUID) {
request.setAttribute("Error", "Session has ended. Please login.");
%> <script>window.location = "LoginPage.jsp";</script><%
}
%>
會話不爲空,但在你的代碼有一些空 – Taha