Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How Do I Use Servlet Filter To Check Session Time-out?  RSS feed

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now, I check session time-out in each of my servlet. People are saying that servlet filter can be used to check session time-out with all JSPs and servlets remain intact.
How do I use servlet filter to check session time-out? Is there an example I can take a look at? Thank you very much.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check whether session exists or not

if session is null it means that either session is nor created or timeout. You can redirect the user to Login page.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have lots of servlets in my application. Right now, I am checking if the session has timed out in each of my servlet.
People say that if I use a servlet filter, all my servlets may remain intact. I would like to see an example of using servlet filter to check session time-out.
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now, I check session time-out in each of my servlet. People are saying that servlet filter can be used to check session time-out with all JSPs and servlets remain intact.
How do I use servlet filter to check session time-out? Is there an example I can take a look at?

Hmm. I am having trouble understanding exactly what you are trying to do. Could you be a bit more specific about what you are trying to accomplish? Maybe you can give a tiny code snippet of what you are already doing so we can see whether/how it could be done in a filter?
Cheers-
- Marty
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put the my above code in Filter and redirect the user to log in page if the user is not logged in or session times out.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java pet store uses Filter for prototected pages which requires user to log in. May be you can have a look aty it.
 
Juan Rolando Prieur-Reza
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
The Java pet store uses Filter for prototected pages which requires user to log in. May be you can have a look aty it.

I think the simple answer to the question would be to call the setMaxInactiveInterval method to control timeout. The example is not enough by itself to answer the original question. The session that JSP "sees" is controlled by the servlet as determined by the MaxInactive Interval setting. This is described in http://java.sun.com/webservices/docs/1.2/api/javax/servlet/http/HttpSession.html for details.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by JiaPei Jen:
[QB]I have lots of servlets in my application. Right now, I am checking if the session has timed out in each of my servlet.
[QB]

JiaPei,
I guess u have developed a pretty poorly designed web app. It will make u more busy on checking the session in each of your servlets...
But I have something for you here... In the following link, which I got from Sun's Enterprise Java Technologies Tech Tips Newsletter every month, it talks about the servlet filter and I do hope that it is suitable for your web app in the current situation... Here it is...
http://developer.java.sun.com/developer/EJTechTips/2002/tt0813.html#tip1
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!