userimage

How to handle the Exceptions in JSP, when session expires?

Currently I am using Struts 1.x in my application.And its uses JSP"s on view layer which are act like display the dynamic content.

But the problem is when session got expired through server in its given time then the pages are break and its display inconsistency

data on the client side(browers) which is quite horrible.

I need some solution to handle this kind of stuffs and display a suitable page to the users.Please help!


userimage
The idea is, Once the user has logged in, a new session is created. Typically, the Login page has the following code

HttpSession session = request.getSession(true);

This does not gaurantee a new session always. If any Session is already active, then a reference to it, is returned. To inactivate any session that is already present and to have a new session,then the code is


HttpSession session = request.getSession(false);

if (session != null)
{
    session.invalidate();
}

session = request.getSession(true);

Then in other servlets where the session is used, the following code should be included.

HttpSession session = request.getSession(false);
if (session == null)
{
    //redirect to login page
}
//other code

And when the user logs out, session can be invalidated.
Answer is