Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirecting on session expired

 
parvez Moinuddin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Eclipse IDE Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use request.isRequestedSessionIdValid()
 
parvez Moinuddin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rupesh Mhatre
Ranch Hand
Posts: 35
Eclipse IDE Hibernate jQuery
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic