0

我的 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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <display-name>tycoon-sa</display-name>

    <context-param>
        <param-name>br.com.caelum.vraptor.encoding</param-name>
        <param-value>UTF-8</param-value>
    </context-param>

    <error-page>
        <location>/</location>
    </error-page>

    <filter>
        <filter-name>vraptor</filter-name>
        <filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>vraptor</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
</web-app>

我的目标是在出现异常或错误代码(404、500 等)时将用户重定向到主页。但它不起作用。我试图访问一个无效的 URL,但我没有被重定向。应用程序抛出 NullPointerException。这是堆栈跟踪:

SEVERE: Servlet.service() for servlet default threw exception  
java.lang.NullPointerException  
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:321)  
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)  
    at br.com.caelum.vraptor.resource.DefaultResourceNotFoundHandler.couldntFind(DefaultResourceNotFoundHandler.java:41)  
    at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:71)  
    at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)  
    at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)  
    at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)  
    at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:91)  
    at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)  
    at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:88)  
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)  
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)  
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)  
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)  
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)  
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)  
    at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:456)  
    at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:327)  
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:193)  
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)  
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)  
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)  
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)  
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)  
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)  
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)  
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
    at java.lang.Thread.run(Unknown Source)  

Abr 02, 2013 11:04:32 AM org.apache.catalina.core.StandardHostValve custom  
SEVERE: Exception Processing ErrorPage[errorCode=0, location=/]  
java.lang.NullPointerException  
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:321)  
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)  
    at br.com.caelum.vraptor.resource.DefaultResourceNotFoundHandler.couldntFind(DefaultResourceNotFoundHandler.java:41)  
    at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:71)  
    at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)  
    at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)  
    at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)  
    at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:91)  
    at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)  
    at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:88)  
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)  
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)  
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)  
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)  
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)  
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)  
    at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:456)  
    at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:327)  
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:193)  
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)  
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)  
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)  
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)  
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)  
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)  
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)  
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
    at java.lang.Thread.run(Unknown Source)  

有什么线索吗?

4

3 回答 3

1

这是为所有错误配置默认错误页面的方法

<error-page>
<location>/whateverpage.html</location>
</error-page>

请记住,这仅在您使用Servlet 3.0时才有效。如果您仍在使用 Servlet 2.5,那么您将必须指定每个错误代码。

<error-page>
<error-code>404</error-code>
<location>/notfound.html</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/general-error.html</location>
</error-page>
于 2013-04-01T06:49:25.080 回答
0

error-page 不能重定向无效的 url。如果你想这样做,你可以使用 apache 服务器并编写以下内容

RewriteEngine on    
Redirect /--xyz-75/ http://www.domain.com.au/
于 2013-04-01T06:27:06.947 回答
0

在错误页面标记 404 /ErrorPage.jsp 中指定错误代码

于 2013-04-01T06:34:28.777 回答