• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session invalidation when user in idle state for particular seconds

 
devi sam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have question on session invalidation. I design the login page by using jsp. i did the business logic in servlet.
I want to invalidate my session after 10 seconds of idle state of user and again i want to redirect to my login page. please help me how to write the code for this task.

i write something like below code , in that code i think some where i did the mistake.
Actually in this i set setMaxInactiveInterval to 10seconds.

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason you don't do this declaratively in web.xml? Seems an easier way to do this.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at <session-timeout> in web.xml
 
devi sam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Any reason you don't do this declaratively in web.xml? Seems an easier way to do this.


ok.. if i give this in web.xml means how can i write the business logic to finish my task.
 
devi sam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:Take a look at <session-timeout> in web.xml


ok... thanks... i had doubt.. my code is correct or not. if you have any code means please suggest me.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether you set the timeout value in web.xml or in your code (after you have logged the user in) you do not invalidate the session yourself. The servlet container does it for you. Why else you even would have a method called setMaxInactiveInterval() if setting it does not have any effect?

So you just check (in a servlet filter preferably or (bad choice) in every servlet in your application) if the session exists and do the redirect if it does not. At least that is one way to do it. Maybe there is a better way to do the redirect in web.xml as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic