Let me explain my problem with the help of following steps.
1. User logs in to the system to see the default main page.
2. He browses through the application, at some point he reaches pageX( There is a link on pageX say linkY).
3. He goes away for some time. His session on server expires in the meantime
4. When he comes back and clicks on linkY of pageX, system redirects him to the login page.
5. Once logged in what he sees is default main page and not desired pageY of linkY
Is there any way I can do this without losing session status of the user when he was on pageY ?
If you implement declarative security for the web app this should happen automatically. The user will be redirected to the page he wanted to see on his next login attempt (when the session expires). Have a look at the auth constrain, web resource collection, security role and related elements in web.xml