Ensure a new session every time the user connects to a Servlet

Posted by Daziplqa on Stack Overflow See other posts from Stack Overflow or by Daziplqa
Published on 2010-05-20T18:54:11Z Indexed on 2010/05/20 19:20 UTC
Read the original article Hit count: 437

Filed under:
|
|

Hi,

I've a JSP/Servlet Web App that consist of more than one servlet (and some JSPs)

I need to create an new HttpSession whenever the users access servlet A, knowing that, servlet A is the home page (i.e. he access it as the first servlet/page in the application)

so far so good, I can write the following code at the start of the servlet A:

HttpSession session = request.getSession(false);
if (session == null) {  
    logger.debug("starting new session...");
    session = request.getSession();
    // other staff here
}

But the problem is, if the user didn't close his browser (even if he closes the tab - in firefox for instance - the session will still be open), so when he try to open my site again, the last session will be re-used (in the rage of session timeout ofcourse), and this I don't need. I need whenever he access Servlet A, he got created a brand new HttpSession.

but unfortunately, he may access this servlet twice per session based on some scenario!!

Please help.

© Stack Overflow or respective owner

Related posts about servlets

Related posts about session