Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

redirect after timeout  RSS feed

 
Bug Menot
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a simpler way to redirect to a page after a session times out?

I dont want to have to create a class that implements HttpSessionListener for something so simple.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
149
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How much simpler can something be than implementing an interface with only two methods?
 
Bug Menot
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well. kinda like

<error-page>
<error-code>TimeOutException</error-code>
<location>/timeout.html</location>
</error-page>


I guess I'll have to use the session listener.
But is there a way to distinguish between a timeout and a harcoded invalidation?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
149
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, what are you trying to do? If you are merely trying to determine if a user's login session has expired, there are more customary patterns that do not involve listening for the session destruction event.
 
Bug Menot
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the deal:
1. User logs in
2. After 10 min. their session times out (using <session-timeout>
3. After that, I want them to be redirected to a timeout page or display a message (not using javascript).

So, what are the customary patterns?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Upon a successfull login, bind an object to the user's session.
With each request, check for the existence of that object.
If it's null, the session is expired so forward or redirect the user to the login screen.

If you're using a Servlet Spec 2.3 compliant or higher container, this check can be done very easily from a filter.

My sessionMonitor example app uses this pattern.
http://simple.souther.us/not-so-simple.html
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
149
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly.
 
Bug Menot
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the Filter better than the Listener in this case? Seems like there's a lot of work involve using Filters.
Is that the most commonly used pattern?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!