handeling JSP会话中的问题

时间:2016-06-22 07:13:34

标签: java jsp session

我在Linux服务器上托管了一个站点。在服务器上,我在日志文件中收到错误消息。

现在我的问题是如何处理Linux服务器上的会话,因为在所有页面上它只考虑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)

if (rs1.next()) {
    HttpSession session = request.getSession();
    session.setAttribute("USERID", rs1.getString("userid"));
    request.getRequestDispatcher("HomePage.jsp").include(request, response);
}

这就是我从Servlet向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><%
    }
%>

这就是我在JSP中处理会话的方式:

propDictionary = globals()
isMtEnabled = propDictionary['convertToMt']

 if isMtEnabled == "true" :
                if props.getProperty("ClusterName") != None and props.getProperty("ClusterName") != "" :
                        print "Have a cluster"
                        clusterNames = clusterName1.split()
                        print "clusterNames is "
                        print clusterNames
                        targetMBeans = []
                        for clusterName in clusterNames:
                                storeName='WseeFileStore_'+clusterName
                                addNamedFileStoreOnServer (storeName,clusterName,distPolicy="Distributed")
 else :
                counter = 0
                c1_arr = []
                c2_arr = []
                for serverName in serverList:
                        if serverName.startswith("c1"):
                                storeName='WseeFileStore_'+serverName
                                addNamedFileStoreOnServer(storeName,serverName,distPolicy="Distributed")
                                jmsServer = addJMSServer(serverName,storeName=storeName)

1 个答案:

答案 0 :(得分:0)

我建议您更改代码

HttpSession session = request.getSession();
String h=null;
if (rs1.next()) {

     h=rs1.getString("userid");

}
 session.setAttribute("USERID", h);
request.getRequestDispatcher("HomePage.jsp").include(request, response);

并用以下内容更改您的文章:

<%
    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) request.getSession().getAttribute("USERID");
    if (null == sessionUID) {
        request.setAttribute("Error", "Session has ended. Please login.");
         %>  <script>window.location = "LoginPage.jsp";</script><%
    }

如果问题仍然存在请验证您与数据库的连接...