Click to See Complete Forum and Search --> : session termination


Aparna
July 10th, 2001, 03:38 AM
Kindly let me know how to log out of a session or how to kill a session.

dlorde
July 10th, 2001, 06:01 AM
Sessions automatically inactivate when no client access is made within the getMaxInactiveInterval time. At this time, all objects are unbound and HttpSessionBindingListeners will get a notification.

To explicitly deactivate a session, call the invalidate() method.

Dave

To email me remove '_spamjam' from my email address

JAI
July 11th, 2001, 04:12 PM
are you talking of sessions with respect to any particular server.
than the server has settings for sessions by default its 20 minutes, in most casses.
if you are talking about sessions in servlet you will have to create special login page and check session there.

In the servlet first check if the Session object exists.

2. If exists check in the session there is a <i>special session object</i>. This special object (here 'UserView' )was already put by our application when a user properly logs into the system.
Basically if a user properly logs in, we create a viewbean object with members loginID, and password and put into memory (put in session with a name like 'userView', so that we can properly check back for the view bean object in session with the nameTag, latter,in any servlet ). This CREATING NEW SESSION and putting a viewBean in session are done in the LoginServlet.

// sample code


code:
--------------------------------------------------------------------------------

if(loginOk == true) { UserView userView = new UserView(loginid, password); //CREATE a NEW session by 'true' argument HttpSession session = request.getSession(true); session.putValue("userView", userView);

--------------------------------------------------------------------------------

3. If that special session object exists, give a GO-AHEAD. Further processiog in the servlet.


4. If not redirect the user to login page/ or a 'notLoggedIn.html' page, and ask the user to PROPERLY LOGIN to the system. I use 'forward' instead of 'redirect' API since this redirect doesn't work properly.


code:
--------------------------------------------------------------------------------

HttpSession session = req.getSession(false);if(session == null) getServletContext().getRequestDispatcher("/app1/login/body_notLoggedIn.html").forward(req, res);if (session != null){ UserView userView = (ams.UserView)session.getValue("userView"); if(userView == null) { System.out.println("User NNooooooooTTTTTT logged!!!!"); getServletContext().getRequestDispatcher("/app1/login/body_notLoggedIn.html").forward(req, res); } else { System.out.println("User logged!!!! ans it has got a USRVIEW in Session also"); }