当我在本地机器上的servlet中检索Session属性时,它们返回正常。但是,当我在远程服务器上执行相同操作时,它们返回null并抛出空指针异常。
设置会话属性
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession sess = request.getSession();
String categoryID = request.getParameterValues("category");
sess.setAttribute("category",categoryID);
RequestDispatcher rd = request.getRequestDispatcher("Questions.jsp");
rd.forward(request, response);
}
检索会话属性
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ClassNotFoundException, SQLException {
HttpSession sess = request.getSession();
String categories = (String) sess.getAttribute("category");
我的web.xml文件看起来像
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>/LabInspection</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
<session-config>
<session-timeout>600</session-timeout>
</session-config>
</glassfish-web-app>