Discussions

Web tier: servlets, JSP, Web frameworks: Mistery dissapearance of a session

  1. Mistery dissapearance of a session (2 messages)

    I have a class which sets session parameters using
    session.putValue( "param1", "value1");
    session.putValue("param2", "value2");

    and then redirects to a JSP page:

    response.sendRedirect( "http://localhost:8889/app/somepage.jsp")

    somepage.jsp retrieves session params using this scriptlet:

    <%
    String param1 = "";
    Object o = pageContext.getAttribute("param1", PageContext.SESSION_SCOPE );
    if ( o != null ) {
    param1 = o.toString();
    out.println("param1 = " + param1);
    }
    String param2 = "";
    o = pageContext.getAttribute("param2", PageContext.SESSION_SCOPE );
    if ( o != null ) {
    param2 = o.toString();
    out.println("param1 = " + param2);
    }
    %>
    ...
    <%@ include file="header.jsp" %>
    ...
    <%
    if (param2.compareTo("") != 0 ) {
    out.flush();
    pageContext.include( "welcome_" + param2 + ".jsp );
    }
    else {
    out.println( "page not included")
    %>
    ...
    <%
    if (param1.compareTo("") != 0) {
    out.flush();
    pageContext.include( param1 + ".jsp" );
    else {
    %>
    ...
    <%@ include file="footer.jsp" %>

    But the attributes retrieved from session here are nulls as I get message "page not included".
    Isn't sendRedirect() supposed to preserve the session and only create a new http request!?

    Threaded Messages (2)

  2. I feel you are not setting the attributes in the Session and trying to read the from the attributes. I hope use of Session.setAttribute() will solve your problem.
  3. I tried that[ Go to top ]

    but no success. putValue is identical functionality as setAttribute. There is some peculiarity with sendRedirect() that I am not aware of. I have no idea what is that, nor I could find answer on Internet, which I searched throughly.
    Just before sendRedirect() I check session and parameter is there. Then sendRedirect() to a JSP page where I tried to read using pageContext and HttpSession, but nothing is there, session got lost. It is a mistery.
    Anybody?