session management??

Discussion in 'JSP' started by adroit89, Apr 19, 2010.

  1. adroit89

    adroit89 New Member

    Joined:
    Jan 5, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    how to manage sessions in JSP. I want to create a session as soon as user logs in and disable the session when he logs out. I also want to disable back button so that when he presses back button login page has to be opened.
     
  2. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    When a user open the broser and done some work or some change and then close the browser then
    it will be stored in cookie and also called the session time in which user access the browser.You can get session ID in jsp by using session.getId() and can set the session user by using session.setAttribute("Session",setsession),
    When user does their work complete and want to close browser,It is called expire or destroy the session.You can find the session starting and ending using session.getCreationTime() and session.getLastAccessedTime() respactively.
    JSP Stores and Retrieves Session Variables as thje following:

    <% @page import = "java.util.Date" session="true"%>
    <html>
    <body>
    <p>JSP (java server page) are required following</p>
    String name="satya";
    session.setAttribute("username",name);
    String user=session.getAttribute("username");
    out.println("Hello" +user);
    Session ID of user in JSP : <%session.getId()%><br>
    Started time of session in JSP<%new Date(session.getCreationTime())%><br>
    expiry time of session in JSP<%new Date(session.getLastAccessedTime())%>
    </body>
    </html>
     

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