Meaningless Drivel is fun!*
The moose likes JSP and the fly likes help with jsp redirection after timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "help with jsp redirection after timeout" Watch "help with jsp redirection after timeout" New topic
Author

help with jsp redirection after timeout

thomas Fuchs
Greenhorn

Joined: Apr 18, 2007
Posts: 16
Hi all

i am looking for help into 2 things;
how to redirect users to a logout page automatically when the session expires,
(i have a lot of jsp/html pages in this web-app, can this be done through tomcat maybe aka globally)
and/or
when a user clicks on a link in a page but his session has expired how to
redirect them to the login page and back again to the original requested link

any help or pointing me in the right direction is greatly appreciated.
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
thomas Fuchs wrote:
when a user clicks on a link in a page but his session has expired how to
redirect them to the login page


You can do it with filters-

This filter would intercept all the requests to those jsps that require that the session has not expired.

In the filter,
check with a request.getSession(false) whether the session doesn't exist.
In that case, do a respone.sendRedirect(loginPage)
If you find that the session exists, you wouldn't have to do anything.


Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Vishwanath Murthi wrote:check with a request.getSession(false) whether the session doesn't exist.

While using a filter is a good idea -- it's how I always do it -- checking the session itself isn't such a good idea. Rather, check for the existence of an authentication token that you place on the session when the user logs in.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Bear Bibeault wrote:checking the session itself isn't such a good idea. Rather, check for the existence of an authentication token that you place on the session when the user logs in.
thanks, good to know.
 
Consider Paul's rocket mass heater.
 
subject: help with jsp redirection after timeout
 
Similar Threads
How can I redirect from sessionDestroyed() of Session Listener
Session timeout problem
redirecting useing session in jsp
redirecting page
Communication between browsers