javaweb_jsp error page

发布时间 2023-06-14 07:05:32作者: ming1010

error page in .jsp

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <%--<%@ page errorPage="error/500.jsp" %>--%>
 3 <%--<%@ page errorPage="error/404.jsp" %>--%>
 4 <%--在xml文件中配置了,该页面就不需要以上声明了--%>
 5 
 6 <html>
 7 <head>
 8     <title>Title</title>
 9 </head>
10 <body>
11 <%
12 int i = 10/0;<%--除数为零,服务器端错误,500-->
13 %>
14 
15 </body>
16 </html>

500.jsp

 1 <html>
 2 <head>
 3     <title>Title</title>
 4 </head>
 5 <body>
 6 <img src="../img/500.jpg" alt="500">
 7 <h1> default 500</h1>
 8 
 9 </body>
10 </html>

 

404.jsp

<html>
<head>
    <title>Title</title>
</head>
<body>
<img src="../img/404.png" alt="404">
<h1> default 404 </h1>

</body>
</html>

error page configuration in .xml

 1 <web-app>
 2   <display-name>Archetype Created Web Application</display-name>
 3   <error-page>
 4     <error-code>500</error-code>
 5     <location>/error/500.jsp</location>
 6   </error-page>
 7   <error-page>
 8     <error-code>404</error-code>
 9     <location>/error/404.jsp</location>
10   </error-page>
11 </web-app>