JBoss Community

HttpSession in JBoss 7 issue

created by Satinder Singh in JBoss AS7 Development - View the full discussion

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>

Reply to this message by going to Community

Start a new discussion in JBoss AS7 Development at Community