JSP Filter with Struts
843838Jan 3 2006 — edited Jan 3 2006Hi,
I am attempting to create a simple JSP Filter for my Struts-based application. The filter is supposed to print a line to stdout any time a JSP is accessed.
The problem I am having is that when I access my JSPs with the following filter mapping, I am not able to see the output in stdout. It's almost like the jsp is not found with the below <url-pattern>:
code:
--------------------------------------------------------------------------------
<filter-mapping>
<filter-name>Test</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
--------------------------------------------------------------------------------
However, if I use a mapping like the one below, then I am able to see the output in stdout for every JSP and every other resource accessed:
code:
--------------------------------------------------------------------------------
<filter-mapping>
<filter-name>Test</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
--------------------------------------------------------------------------------
My goal is find a way to only see the ouptut in stdout for JSPs and not everything else. Please advise!
Thanks!
My code:
code:
--------------------------------------------------------------------------------
package com.test;
import org.apache.log4j.Logger;
import javax.servlet.*;
import java.io.IOException;
public class TestFilter implements Filter {
private static Logger LOG = Logger.getLogger(TestFilter.class); private FilterConfig filterConfig;
public void doFilter(final ServletRequest request,final ServletResponse response, FilterChain chain) throws IOException, ServletException {
LOG.debug("============Entering Filter");
chain.doFilter(request,response);
LOG.debug("============Exiting Filter");
}
public FilterConfig getFilterConfig() {
return filterConfig;
}
public void init(FilterConfig config) {
this.filterConfig = config;
}
public void destroy() {
this.filterConfig = null;
}
}
--------------------------------------------------------------------------------
code:
--------------------------------------------------------------------------------
<filter>
<filter-name>Test</filter-name>
<filter-class>com.test.TestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Test</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
--------------------------------------------------------------------------------