0
我试图用我定义我的过滤器这样的[Q]如何捕捉错误404:SRVE0190E
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
}
}
我定义我的包装像这样的web.xml中定义的过滤器捕捉到404错误:
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>
但不捕捉40 4错误,只是在url映射到ActionServlet映射的url时调用过滤器,这意味着,用.do 完成我尝试更改WAS com.ibm.ws.webcontainer.invokeFiltersCompatibility = true中的属性,但仍然没有工作和我没有任何其他想法如何解决它,任何帮助将不胜感激。
参见[最佳方式来处理404 - 找不到网页的错误在JSP](http://www.theserverside.com/discussions/thread.tss?thread_id=29287# 165503) – 2012-03-21 21:14:42
是的,我试过,但没有工作,我添加了错误页面,没有任何内容...,我认为问题与WAS有关,因为在调试过程中调用了任何过滤器...我不知道为什么 – DGomez 2012-03-21 21:20:34
因此,问题是当WAS在尝试访问不存在的页面时发生404错误时,不会调用过滤器......但是当URL以.do结尾时,将调用过滤器。 ..,任何人都知道为什么有这种行为? – DGomez 2012-03-22 12:58:56