I do something similar. I don't know which version of Struts you are using,
but I decided to create a general SessionTimeoutException and forward the
User to a SessionTimeout page when that error occurs. I'm simply configured
a GeneralFoward for the SessionTimeout page.

        protected void ensureSessionSecurity(HttpServletRequest request)
throws AzDiasMinerSessionTimeoutException
        {
                HttpSession session = request.getSession(false);
                
                if(session == null || session.isNew()) 
                {
                        session.invalidate();
                        throw new AzDiasMinerSessionTimeoutException();
                }
        }

On the respective page the User can read about the Timeout. You just need to
catch and forward on this exception.

                }
                catch(AzDiasMinerSessionTimeoutException ase)
                {
                        return mapping.findForward("session_timeout");

                }

I also did that in a subclass of Action.
PLEASE NOTE: You have to check for isNew() cause Tomcat e.g. creates a new
session even if your call getSession() with false.  The Specs say that null
should normally be returned instead.





-----Ursprüngliche Nachricht-----
Von: Sanoj, Antony (IE10) [mailto:[EMAIL PROTECTED]
Gesendet: Freitag, 19. März 2004 10:48
An: [EMAIL PROTECTED]
Betreff: SessionTimeout handling


Hi,
I am trying to handle session timeout by extending the ActionServlet.
I am trying to use the request method isRequestedSessionIdValid() coupled
with checking the session for my userbean. 
Please comment about this code. Advice if there is a better way to do
session timeout trapping.
/***************************************************************************
***/
 public boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response) 
 {
   /* "UserBean" is a bean which represents the logged in user. */  
  if( request.isRequestedSessionIdValid() ||
request.getSession().getAttribute("UserBean") != null)
       return true;
  else
  {
   try
   {
 
request.getRequestDispatcher("SessionTimeout.do").forward(request,response);
   } 
   catch(Exception e)
   {
          e.printStackTrace();  
   }
   return false;
  }
 }
/***************************************************************************
***/
Regards, 
Sanoj Antony 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to