• 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 to automatically display SessionExpired.jsp upon session timeout ?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a Struts application in which we are setting the session timeout time in Web.xml and listening the session time out using a class implementing 'HttpSessionBindingListener'.

Webshphere Application Server 5.0.x

Upon session timeout 'valueUnbound' method gets called.
Requirement is to direct user to a particular 'SessionExpired.jsp' from this method.

Setting 'response' in 'session' in every Action that is called.

Inside 'vlaueUnbound(HttpSessionBindingEvent event)' I am doing the following:
1) HttpSession session = event.getSession();
2) Retrieve the 'response' from 'session'.
3) Call response.sendRedirect("/view/jsp/common/SessionExpired.jsp");

I am getting an exception on response.sendRedirect...

java.lang.IllegalStateException: Context has not been prepared for next connection
:
:

Any other method that I should call or any other technique that we should use. Objective can be achieved from JSP also but we want ot do this from server side only.
 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Himanshu,

Since you are using struts you can handle session expiry in RequestProcessor Class.

Since all the requests are intercepted by processPreprocess() of RequestProcessor Class you can create a CustomRequestProcessor for your application and write the session expiry logic there.

Hope this helps.

Regards,
Vineela
 
Himanshoo Vijay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue is that I want to generate a response to client upon session expiration, but that resoponse should have proper context as is generated by Websphere container when it makes available a request and response object to Action's execute method.

So should I write a CustomRequestProcessor implementing HttpSessionBindignListener? The valueUnbound gets called automatically upon session expiration, but what to call next ?
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Inside 'vlaueUnbound(HttpSessionBindingEvent event)' I am doing the following:
1) HttpSession session = event.getSession();
2) Retrieve the 'response' from 'session'.
3) Call response.sendRedirect("/view/jsp/common/SessionExpired.jsp");



No, I believe you can only call response.sendRedirect() inside a servlet processing a request - not in
a Listener.


Upon session timeout 'valueUnbound' method gets called.
Requirement is to direct user to a particular 'SessionExpired.jsp' from this method.



Do you mean "pushing" some content to the client browser when the session expires. As far as I know, this is not possible with HTTP. You can only display session expired info whenever the client make a new request. You need to check for the existence of match HttpSesion object for every client request. And, as mentioned by Vineela, it is best done inside Struts' ActionServlet (i.e. by using RequestProcessor) since all request are intercepted by it.
 
Ranch Hand
Posts: 63
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vineela/Alec/Himanshoo
Agreed to approach of implemneting the CustomRequestProcessor

further to this discussion,please comment if what i am suggesting below is a feasible solution.instead of keeping the response in session,we keep the request in session and use the requestDispatcher object to forward to the error jsp SessionExpired.jsp

Will this work?is this a good approach?
thanks in advance
cheers
vinny m
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


instead of keeping the response in session,we keep the request in session and use the requestDispatcher object to forward to the error jsp SessionExpired.jsp


You don't keep the response/request object in the session. They are automatically created (and destroyed) on each request by the container. What you should do in your CustomRequestProcessor might be something like this:

HttpSession session=request.getSession(false);
if (session==null) {
// test the request url to see if this is a constrained resource
// if yes, forward to SessionExpired.jsp/Login.jsp
// if no, create a new session and forward to that page.
}
...
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Could any one supply the code of CustomerRequestProcess..?


I need for the same requirement


ThanksInadvance
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic