DoFilter does not receive a call

Could you help check why doFilter is not getting a call

web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <filter> <filter-name>roseFilter</filter-name> <filter-class>net.paoding.rose.RoseFilter</filter-class> </filter> <filter-mapping> <filter-name>roseFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> </web-app> 

class signature:

 import org.springframework.web.filter.GenericFilterBean; public class RoseFilter extends GenericFilterBean { 

404 is returned during a call to http: // localhost: 8080 / hello / world , I set breakpoints on doFilter, it seems doFilter is not called? (I tried tomcat 6.0.18, 6.0.29, jdk1.6)

+7
java servlets servlet-filters
source share
2 answers

The filter will not be called if:

  • The filter class is missing from the class path and / or does not load or cannot be loaded. However, you should notice this in the server startup logs. A solution should be found based on the interpretation of exceptions / errors found in server logs.

  • Another filter running in the chain that does not call FilterChain#doFilter() , but rather RequestDispatcher#forward() or include() , which led to the fact that subsequent filters in the chain were completely skipped (when they do not listen to FORWARD controllers or INCLUDE , by default they only listen to the REQUEST dispatcher). The solution is either to fix the wrong filter, or add <dispatcher>FORWARD</dispatcher> , etc. Accordingly, either reorder the filter declarations in web.xml so that your new filter appears before another filter (you, in turn, only need to make sure that your new filter uses FilterChain#doFilter() correctly :)).

  • The request URL is incorrect. You used http: // localhost: 8080 / hello / world . When listening to a filter on /* this means that the webapp context must be ROOT or at least /hello . Check your webapp context. I will just try again with a URL that points to a valid JSP / Servlet inside the same webapp that generates a non-404 response. Is the filter also called?

+21
source share

What does a web request look like? Can you try changing your url pattern to *. Jsp instead of / *? If you are using something other than pure JSP, then change it to something that has an extension ending with the request (for example, for struts this is usually * .do).

0
source share

All Articles