#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Hyderabad, India
    Posts
    19
    Rep Power
    0

    Unhappy Problems with sessions


    I am new to development in JSP/Servlets. I am trying to develop a simple login authorization system using sevlets. For this I am using a simple html based logon form. On submit i am invoking a servlet which does the authentication and creates a session.

    HttpSession session = request.getSession(false);
    session.setAttribute("fusion.user", uName);
    session.setAttribute("fusion.auth", "Y");
    String eURL = response.encodeRedirectURL(tURL);
    response.sendRedirect(eURL);


    The problem is I am unable to retrieve the session variable set in the servlet in the subsequent redirected jsp page. The session variables are showing as NULL.


    <%
    session = request.getSession(false);
    String name = (String) session.getAttribute("fusion.user");
    String authe = (String) session.getAttribute("fusion.auth");

    out.print("<BR>");
    out.print(name);
    out.print("<BR>");
    out.print(authe);
    %>

    Could somebody help me on this. I am enclosing the servlet code along with this message.

    Thanx in advance

    Ramesh
    Attached Files
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    First of all, I don't think you want to use the boolean form of the getSession in your servlet. Sending flase to that method will NOT return a session if one has not been created already. If this is a user first logging in they probably won't have a session already. Try this instead
    Code:
    HttpSession session = request.getSession();
    Secondly, the "session" variable is already available in a jsp. It is implicitly available to all jsp's unless you specify that it should not be. You are overwriting the implicit variable when calling
    Code:
    session = request.getSession(false);
    in you jsp. Delete that line and see what happens
    Code:
    <%
    String name = (String) session.getAttribute("fusion.user");
    String authe = (String) session.getAttribute("fusion.auth");
    
    out.print("<BR>");
    out.print(name);
    out.print("<BR>");
    out.print(authe);
    %>
    Lastly, you don't show the url you request and the url you redirect to. If the browser does not think they are the exact same host it will not send the cookie for the session.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Hyderabad, India
    Posts
    19
    Rep Power
    0

    Thumbs up


    Thanx Nemi.. It works now. The problem was a combination of the boolean type of getSession and that I was passing the complete URL in the sendRedirect instead of the absolute path.

    Thanx once again.

    Ramesh

IMN logo majestic logo threadwatch logo seochat tools logo