【问题标题】:Spring mvc <error-page> not workingSpring mvc <error-page> 不工作
【发布时间】:2017-08-20 14:26:00
【问题描述】:

我一直在搜索并尝试各种不同的方法来映射我的自定义 404 页面,但到目前为止没有任何效果。以下是我的 web.xml:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">
  <display-name>Spring3 MVC Application</display-name>

  <servlet>
    <servlet-name>spring-web</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
      <init-param>
          <param-name>throwExceptionIfNoHandlerFound</param-name>
          <param-value>true</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern>/</url-pattern>
      <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/views/404.jsp</location>
    </error-page>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-web-servlet.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

</web-app>

我尝试过设置错误页面标记或设置 IfNoHandlerFound 异常。似乎没有任何工作。如果需要更多代码或信息,请告诉我。感谢您的帮助。

【问题讨论】:

    标签: spring spring-mvc error-handling http-status-code-404 custom-error-pages


    【解决方案1】:

    验证您页面的真实位置:&lt;location&gt;/WEB-INF/views/404.jsp&lt;/location&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多