Scott,

I recommend you use getRequestURI to check against the path
(context-relative) you want to protect. Also, it's possible you're seeing
hits against the images in your page (10 images will call your filter 10
times).

Thanks,
Paul

-----Original Message-----
From: Scott Purcell [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 27, 2005 10:20 AM
To: user@struts.apache.org
Subject: Filter Being Called Repeatedly


Hello,
I decided to try and implement a filter for my struts application. A filter
that would check for a session object, and if it does not exist, send the
user to a certain link.

Anyway, I found an example in the "Struts Cookbook" and I am implementing
it. But for whatever reason, when I hit a page that should redirect me, I
can see (by debug statements) that the filter is hit 10 or more times, and
then I get an error stating: "Redirect limit for this URL exceeeded. Unable
to load the requested page") in an alert Box?

I would really like to get this going:
Here is the code, and the web.xml I am using. Any help would be appreciated.

CODE
public class AppFilter implements Filter {

  private String onFailure = "index.jsp";
  private FilterConfig filterConfig;

  public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    onFailure = filterConfig.getInitParameter("onFailure");
  }

  public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
    throws IOException, ServletException {


    Logger log = Logger.getLogger(this.getClass().getName());
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    log.info("XXXXXXXXXXXXX");
    log.info("AppFilter called for a request.");
    log.info("param onFailure=" + onFailure);

    // if the page is onFailure page continue down the chain
    if (req.getServletPath().equals(onFailure)) {
      log.info("YYYY equals YYYY");
      chain.doFilter(request, response);
      return;
    }


    HttpSession session = req.getSession();
    AppObject appObject = (AppObject)session.getAttribute("APP_OBJECT");
    if (appObject == null) {
      log.info("AppObject is null, send to front door.");
      log.info("sending path=" + req.getContextPath() + onFailure);
      resp.sendRedirect(req.getContextPath() + onFailure);
      return;
    } else {
      log.info("DDDDDDDD");
      chain.doFilter(request, response);
    }
  }

  public void destroy() {
  }
}


WEB.XML
<filter>
    <filter-name>AppFilter</filter-name>
    <filter-class>com.mb.purcell.app.AppFilter</filter-class>
    <init-param>
      <param-name>onFailure</param-name>
      <param-value>/index.jsp</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>AppFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

Thanks,

Scott K Purcell

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





------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments, contains 
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New 
Jersey, USA 08889), and/or its affiliates (which may be known outside the 
United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as 
Banyu) that may be confidential, proprietary copyrighted and/or legally 
privileged. It is intended solely for the use of the individual or entity named 
on this message.  If you are not the intended recipient, and have received this 
message in error, please notify us immediately by reply e-mail and then delete 
it from your system.
------------------------------------------------------------------------------

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

Reply via email to