【问题标题】:404 error not mapping with error page404 错误未与错误页面映射
【发布时间】:2013-08-09 07:46:19
【问题描述】:

我已将 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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <!-- Config here. -->
<servlet>
    <servlet-name>SpringConfig</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>SpringConfig</servlet-name>
        <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath: SpringConfig.xml</param-value>
  </context-param>

  <listener>    

    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

  </listener>

  <error-page>
    <exception-type>404</exception-type>
    <location>/404error.html</location>
   </error-page>

</web-app>

这是我位于 WebContent 文件夹中的简单 404error.html 页面:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
The Page You Are Looking For Is Not Available.
</body>
</html>

但是我没有超过自定义页面,你们能告诉我我缺少什么吗?

【问题讨论】:

    标签: java spring servlets web.xml


    【解决方案1】:

    这似乎是您在 web.xml 中提到的 htm 而不是 html 用于此处提到的 web.xml 中的 servlet-mapping 的拼写错误:

        <url-pattern>*.htm</url-pattern>
    

    尝试将其更改为:

        <url-pattern>*.html</url-pattern>
    

    【讨论】:

    • 这不是拼写错误,我在spring配置文件中使用视图解析器将.htm url映射到我的.jsp
    【解决方案2】:

    exception-type 更改为exception-code

    <error-page>
        <exception-code>404</exception-code>
        <location>/404error.html</location>
    </error-page>
    

    【讨论】:

      【解决方案3】:

      试试这个。它在我的所有应用程序中都运行良好。

      <error-page>
              <error-code>404</error-code>
              <location>/404error.html</location>
      </error-page>
      

      【讨论】:

        猜你喜欢
        • 2014-07-12
        • 2015-06-22
        • 2020-06-21
        • 2012-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-12
        • 2015-03-30
        相关资源
        最近更新 更多