aspose file tools*
The moose likes Servlets and the fly likes Redirecting on session expired Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirecting on session expired" Watch "Redirecting on session expired" New topic
Author

Redirecting on session expired

parvez Moinuddin
Greenhorn

Joined: May 05, 2011
Posts: 3
Hi All,
Can anybody please let me know how can I achieve the below task
I want that if the user is idle for say 5 minutes it should be redirected to Log in page
I tried the following things but unable to achieve the result
1. I configured web.xml and added
<session-config>
<session-timeout>5</session-timeout>
</session-config>

I am able to make the session expire after 5 mins
But how can I make it automatically redirected to Login page.

Please let me know about that
Parvez
Rupesh Mhatre
Ranch Hand

Joined: Apr 29, 2011
Posts: 35

You can use request.isRequestedSessionIdValid()
parvez Moinuddin
Greenhorn

Joined: May 05, 2011
Posts: 3
Rupesh Mhatre wrote:You can use request.isRequestedSessionIdValid()

@ Rupesh
Hi I tried that but still not working
Can you please elaborate on that
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

parvez Moinuddin wrote:But how can I make it automatically redirected to Login page.

You'll have to explain what you mean by this.

If you mean that, all by itself, the page should redirect when the session expires, well that's impossible. Without making any request back to the server, how would the browser know that the session has expired? Think about that.

Rather than relying on the session timeout, do you really need a client-side JavaScript timer?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rupesh Mhatre
Ranch Hand

Joined: Apr 29, 2011
Posts: 35

request.isRequestedSessionIdValid() will give you boolean return if session is valid. As Bear Bibeault has already explained this can not happen automatically and you have to set JS timer for that nut using this atleast you can take care that if user is on the same page till timeout happens and try making new request it will redirect user to your session expire page for this you have to place your code inside the if block having this check condition.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirecting on session expired