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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to