我正在尝试使用web.xml中定义的过滤器捕获404错误我定义了我的过滤器
public class StatusValidationFilter implements Filter
{
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse,
FilterChain filterchain) throws IOException, ServletException
{
HttpServletResponse response = (HttpServletResponse)servletresponse;
if (!(response instanceof StatusExposingServletResponse))
{
response = new StatusExposingServletResponse(response);
}
filterchain.doFilter(servletrequest, response);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
我像这样定义了我的包装器:
public class StatusExposingServletResponse extends HttpServletResponseWrapper
{
public StatusExposingServletResponse(HttpServletResponse response) {
super(response);
}
public void sendError(int sc) throws IOException {
if(sc == HttpServletResponse.SC_NOT_FOUND)
{
throw new RuntimeException();
}
super.sendError(sc);
}
public void sendRedirect(String location) throws IOException {
super.sendRedirect(location);
}
}
好的,然后在web.xml中定义了过滤器和映射,如下所示:
<filter>
<filter-name>StatusValidationFilter</filter-name>
<filter-class>com.test.StatusValidationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>StatusValidationFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
但是没有捕获404错误,只是在url映射到ActionServlet映射的url时调用过滤器,这意味着,完成.do 我尝试更改WAS com.ibm.ws.webcontainer.invokeFiltersCompatibility = true中的属性,但仍然无法正常工作,我对其如何修复没有任何其他想法,任何帮助都会受到赞赏。
答案 0 :(得分:0)
您需要设置
com.ibm.ws.webcontainer.invokefilterscompatibility=true
服务器中的- &gt;服务器 - &gt; Web容器设置 - &gt; Web容器 - &gt;自定义属性。
详情请见:http://frightanic.com/software-development/solution-to-error-404-srve0190e-on-websphere-6-1