自定义404错误页面未显示

时间:2015-06-13 05:36:22

标签: jsp http-status-code-404 web.xml

我正在尝试使用以下代码向我的应用程序提供自定义错误页面,例如PageNotFoundNullPointerException

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" 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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Raptor 1-5</display-name>
  <welcome-file-list>
    <welcome-file>LoginPage.jsp</welcome-file>
  </welcome-file-list>
  <error-page>
  <error-code>404</error-code>
  <location>/404ErrorPage.jsp</location>
  </error-page>

  <error-page>
  <exception-type>PageNotFoundException</exception-type>
  <location>/404ErrorPage.jsp</location>
  </error-page>

</web-app>

UrlSecurityCheckingPage.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isErrorPage="true" errorPage="404ErrorPage.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>break url and check whether displays custom 404 error page or not.</h1>

</body>
</html>

404ErrorPage.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>This page may be broken or not valid.</h1>
<br>
<a href="LoginPage.jsp">Click Here to Login Page.</a>
</body>
</html>

当我提供真实路径http://localhost:8080/Raptor1-5/UrlSecurityCheckingPage.jsp时,它会显示页面,但是当我提供不完整的网址http://localhost:8080/Raptor1-5/UrlSecurityCheckingPa时,它会显示默认的404错误页面,而不是我的自定义错误页面。

如何解决这个问题?我在哪里做错了?

0 个答案:

没有答案