JSP Session

Discussion in 'JSP' started by virendrachandak, Jun 26, 2010.

  1. virendrachandak

    virendrachandak New Member

    Joined:
    Jun 26, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I need help with JSP session.

    My problem:
    I have a login page. When a user logs in then, i set a session and its expiration time. So, when the session is expired, the user will be redirected to the login page with a session expired message.
    I want to identify if a page has been loaded first time by the user, or it has been loaded as a result of expiration of session.

    My code:

    I do the following when the user successfully logs in:
    Code:
    session.setAttribute("username",user_id);
    session.setMaxInactiveInterval(600);
    
    I check this in every page (i.e. check in the header of everypage)

    Code:
    String username = (String) session.getAttribute("username");
     
    if (session.isNew() == true && username == "")
    {
        response.sendRedirect("login.jsp?rtype=expired");
    }
    else
    {
        //check the credentials
    }
    
    Also when the user logs out the following code is executed:
    Code:
    session.invalidate();
    My problem is that even when the user comes to the page for first time, it redirects the user to "login.jsp?rtype=expired" page.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice