You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Samanth Athrey <sa...@azikewe.com> on 2003/11/05 16:26:16 UTC

Handling Session Timeout

Hello Gurus

I am trying to handle session timeout by extending RequestProcessor. Since
the processPreprocess(...) method is called before the Action.execute(..)
method, am trying to add that piece of code to check if the session is
valid. The problem am facing is, if i return false from this method, the
requestProcessor will stop processing and return the control back to doGet
or doPost method in ActionServlet. How do I redirect it to login.jsp or
index.jsp from there? Any help/tips would be really great.

Thanx.
Sam




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Handling Session Timeout

Posted by Rick Reumann <st...@reumann.net>.
Samanth Athrey wrote:

> I am trying to handle session timeout by extending RequestProcessor. Since
> the processPreprocess(...) method is called before the Action.execute(..)
> method, am trying to add that piece of code to check if the session is
> valid. The problem am facing is, if i return false from this method, the
> requestProcessor will stop processing and return the control back to doGet
> or doPost method in ActionServlet. How do I redirect it to login.jsp or
> index.jsp from there? Any help/tips would be really great.

Rather than do this in a subclass of RequestProcessor, I usually 
have all my Actions extend a Base action (a base DispatchAction 
actually) and in there I override the execute method and do 
something like...


public ActionForward execute(final ActionMapping mapping, final 
ActionForm form, final HttpServletRequest request, final 
HttpServletResponse response) throws Exception {
     HttpSession session = request.getSession(false);
     if (session == null || session.getAttribute("loggedOut") != 
null ) {
         //user doesn't have a session or they loggedOut using the 
logout button
         return mapping.findForward(Const.GOTO_LOGIN);
     } else if ( session.getAttribute("userBean") == null ) {
         //user has a session, but no userBean in scope so therefore 
session has timed out
         ActionMessages messages = new ActionMessages();
         messages.add(ActionMessages.GLOBAL_MESSAGE, new 
ActionMessage("message.session.expired") );
         saveMessages(request, messages);
         return mapping.findForward(Const.GOTO_LOGIN);
     } else  {
         //user is already logged in so
         //call super class method which will call apropriate 
dispatch method in subclass
         return super.execute(mapping, form, request, response);
     }
}

-- 
Rick


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org