This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes HttpServletResponse in HttpSessionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletResponse in HttpSessionListener" Watch "HttpServletResponse in HttpSessionListener" New topic
Author

HttpServletResponse in HttpSessionListener

John Eric Hamacher
Ranch Hand

Joined: Apr 25, 2007
Posts: 230
Hello:

I'd like to redirect the user to a login page from within my HttpSessionListener. I cannot find a way to get a hold of the HttpServletResponse object. Can anybody help me?

Thanks
eric
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41092
    
  44
The point of using listeners generally is to decouple various pieces of code from one another. Code that runs when a session is created or deleted shouldn't be mixed up with code that decides how a response is created.

But there must be a piece of code that creates (or invalidates) the session, thus leading to the event listener being called. Maybe the logic for determining the response would fit in there?


Ping & DNS - my free Android networking tools app
John Eric Hamacher
Ranch Hand

Joined: Apr 25, 2007
Posts: 230
Thank you for responding.

Actually I am trying to handle session timeouts. I think I may use a Filter to check my session and redirect.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HttpServletResponse in HttpSessionListener
 
Similar Threads
Regarding Servlets
inside the class that implements HttpSessionListener
Getting access to HttpServletResponse with in sessionDestroyed Method of HttpSessionListener
About Sessions
Get Total session count