SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: JSP Session

  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JSP Session

    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.

  2. #2
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The check of 'session.isNew()' is most likely always returning true during the first time a user visits your site.

    http://java.sun.com/products/servlet...mr2/index.html
    baby steps... baby steps...

  3. #3
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try using

    // Create one if it doesnt exist or else return the existing one
    HttpSession session = request.getSession(true)
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •