关于tomcat的filter,调用chain.doFilter(request, response)就出现404错误
不调用就什么都不显示,不显示是正确的吧public class SetCharacterEncodingFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
String browserDet = ((HttpServletRequest)request).getRequestURI();
System.out.println(browserDet);
chain.doFilter(request, response);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
System.out.println("destroy..");
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
System.out.println("init..");
}
}
web.xml配置
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<filter>
<filter-name>test-filter</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>test-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app> --------------------编程问答-------------------- 《JAVA WEB 实战经典》一书283页的提示中有提到
由于跳转路径的问题,有可能造成404的路径错误。
还说可以参照书后讲解的应用范例(就是没找到= = --------------------编程问答-------------------- 找到问题了没有
补充:Java , Web 开发