• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic