2 Replies Latest reply on Jul 22, 2011 12:40 AM by Satinder Singh

    HttpSession in JBoss 7 issue

    Satinder Singh Newbie

      I set an attribute in an HttpSession (in Servlet) and tried to read the same in the subsequent Servlet call. But the session returns a null value for the parameter. Am I missing something? The same code works fine in JBoss 6 and Glassfish.

       

      The simple code is as below:

       

              String mode=request.getParameter("mode");

              String message=null;

              if (mode.equals("1")){

                  HttpSession session=request.getSession(true);

                  session.setAttribute("SOMEPARAM", "SOMEVAL");

                  message="Value set in session "+session.getAttribute("SOMEPARAM");

              }else if (mode.equals("2")){

                  HttpSession session=request.getSession(true);

                  message="Value read from session "+session.getAttribute("SOMEPARAM");

              }

             

              PrintWriter pw=response.getWriter();

              pw.print("<html><head><title>Test Session</title></head><body><h1>"+message+"</h1>");

              pw.print("</body></html>");

              pw.flush();

         

      And a very simple JSP to invoke this

       

      <p><a href="/TestJBoss/TestServlet?mode=1">Write to Session</a></p>

      <p><a href="/TestJBoss/TestServlet?mode=2">Read from Session</a></p>