struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Lipscombe" <adam.lipsco...@expensys.com>
Subject RE: Best practice for redirecting on session timeout?[Scanned]
Date Fri, 13 May 2005 10:19:44 GMT
Folks


Many thanks for all your input on this. I decided to go with the filter
approach.
My doFilter() method is below. I certainly traps the timeout.

The problem now is that the redirect fails no matter if I use
"/pages/SessionTimedOut.jsp" or a fully qualified URL (e.g
"http://localhost:8080/ExpenSysWT/pages/SessionTimedOut.jsp")


The error message that is logged is: "failed to set redirect, msg = null"


Any help much appreciated


TIA -Adam






----------------------

  public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
  {
    HttpServletRequest  httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse)
response;
    HttpSession httpSession = httpServletRequest.getSession();

    boolean sessionTimedOut = false;

    try
    {
      if (false == httpServletRequest.isRequestedSessionIdValid())
      {
        sessionTimedOut = true;
      }
      else
      {
        String requestedAction = httpServletRequest.getRequestURI();
        if (false == requestedAction.endsWith(StrutsConstants.LOGIN_ACTION))
        {
          if (null != httpSession)
          {
            if (null == httpSession.getAttribute(Constants.SESSION_CONTEXT))
            {
              sessionTimedOut = true;
            }
          }
        }
      }

      if (true == sessionTimedOut)
      {
        logger.warning("session timed out");
        httpServletResponse.sendRedirect("/pages/SessionTimedOut.jsp");
      }

      chain.doFilter(request, response);

    }
    catch (Exception ex)
    {
      String msg = "failed to set redirect, msg = " + ex.getMessage();
      logger.severe(msg);
    }
  }


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


Mime
View raw message