未经检查的异常未被Web.xml错误页面捕获

时间:2011-07-10 17:54:40

标签: java servlets servlet-filters web.xml

我有一个未经检查的异常,未被指定的web.xml错误页面处理。我的目录设置如下:

/index.jsp

/error.jsp

/WEB-INF/web.xml

/其他页面&这里的目录

我在web.xml中指定了以下内容:

    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/error.jsp</location>
    </error-page>

    <error-page>
        <error-code>500</error-code>
        <location>/error.jsp</location>
    </error-page>

但是,当我故意通过创建错误对象在我的登录Servlet中抛出IllegalArgumentException时,应用程序只是吃掉错误并将其记录在Tomcat 6.0 Log中。该页面未被重定向到error.jsp页面。

我做错了什么?如果您需要更多信息帮助,请告诉我们。以下是Tomcat 6.0 Log中的错误信息:

  

SEVERE:Servlet的Servlet.service()   AccountSignIn抛出异常   java.lang.IllegalArgumentException异常:   int id无效   FindMeInfo.getInstance(),id:-1           在com.blank.groupandpal.FindMeInfo.getInstance(FindMeInfo.java:15)           在com.blank.accounts.servs.AccountSignInServlet.processRequest(AccountSignInServlet.java:107)           在com.blank.accounts.servs.AccountSignInServlet.doPost(AccountSignInServlet.java:164)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:637)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)           在com.blank.filters.SessionAuthFilter.doFilter(SessionAuthFilter.java:79)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)           在com.blank.filters.IPControlFilter.doFilter(IPControlFilter.java:97)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)           在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)           在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)           在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)           在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)           在ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:158)           在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)           在org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)           在org.apache.coyote.http11.Http11AprProtocol $ Http11ConnectionHandler.process(Http11AprProtocol.java:574)           在org.apache.tomcat.util.net.AprEndpoint $ Worker.run(AprEndpoint.java:1527)           在java.lang.Thread.run(Thread.java:595)

谢谢。

1 个答案:

答案 0 :(得分:2)

我似乎记得在调用过滤器的doFilter方法期间禁用了错误页面机制。您可能会考虑让最外层的过滤器充当您自己的错误页面处理程序。

基于评论的其他信息:
错误页面机制已针对请求禁用,因为它正由一个或多个过滤器处理(例如IPControlFilterSessionAuthFilter)。它与将过滤器应用于错误页面没有任何关系。我提到的“最外层过滤器”将映射到/*,并且只会执行以下操作:

try {
    chain.doFilter(request, response);
} catch (Throwable exc) {
    // set request attributes to capture error info and then forward to error page (e.g. /error.jsp)
}

换句话说,这个过滤器本质上是错误页面机制的再创造......