1. On session timeout,whose value is set in web.xml, if the session is invalid,throw an exception and invalidate the session. 2. If the user closes the brwoser directly,invalidate the session.
Here,I am not able to invaildate the session.Every time I open a new browser,taking the previous session.I guess
In case of 1. I should redirect the exception page to another temp jsp which will invalidate the session. 2. On form unLoad ,call a servlet which will invalidate the session.However once the sessionis invalidated,becomes null,throws a blank page.
Am I on the right track?Any code snippets,pointers ... will be helpful.
Code Snippet in the servlet: /** To check whether the session already exists or not * if the session does not exist,creating a new session * * if the session already exists,check whether it is valid or not * if the session is already valid,do the normal processing * else,throw an exception */ String forward; HttpSession session = request.getSession(); System.out.println("session", session); System.out.println("IdValid" + request.isRequestedSessionIdValid()); if ( null == session ) { session = request.getSession(true); Trace.data("Got a new one session", session); /** do the usual processing creation of the forward string ----------------------------------- ----------------------------------- **/
} else { //Trace.data("Session existing before the user logged in ", session); if (request.isRequestedSessionIdValid()) {
/* If the session exists and is valid use the same sesion */ Trace.checkpoint("Valid Session"); /** do the usual processing creation of the forward string ----------------------------------- ----------------------------------- **/
} else { /* The session exists but is invalid throw an exception */ Trace.checkpoint("Invalid Session"); Trace.checkpoint("Closing the Session"); // If I invalidate the sessionhere,it will become //null,blank page //session.invalidate(); //Throw Exception,forward string = error page