This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes session invalidation when user in idle state for particular seconds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "session invalidation when user in idle state for particular seconds" Watch "session invalidation when user in idle state for particular seconds" New topic
Author

session invalidation when user in idle state for particular seconds

devi sam
Greenhorn

Joined: Nov 25, 2010
Posts: 9
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

Joined: Apr 14, 2004
Posts: 10336

Any reason you don't do this declaratively in web.xml? Seems an easier way to do this.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Take a look at <session-timeout> in web.xml


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
devi sam
Greenhorn

Joined: Nov 25, 2010
Posts: 9
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

Joined: Nov 25, 2010
Posts: 9
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

Joined: Apr 15, 2008
Posts: 198
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: session invalidation when user in idle state for particular seconds
 
Similar Threads
session keeps timing out
How to clear a JTextField!!
ques
Beginner needs help!!
How to determine if a session has expired...