vendredi 12 juin 2015

J2EE - custom 404 error page not display

I am trying to give custom error page to my application like PageNotFound or NullPionterException using below code,

Web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://ift.tt/ra1lAU" xmlns="http://ift.tt/nSRXKP" xmlns:web="http://ift.tt/LU8AHS" xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/1eWqHMP" 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://ift.tt/kTyqzh">
<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://ift.tt/kTyqzh">
<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>

when i give real path http://localhost:8080/Raptor1-5/UrlSecurityCheckingPage.jsp its display the page but when i broke the url like http://localhost:8080/Raptor1-5/UrlSecurityCheckingPa its shows default 404 error page only instead of my custom error page.

How to fix this? where am i doing wrong?

Aucun commentaire:

Enregistrer un commentaire