一、跳轉頁面的2種方法
註釋:文件結構如圖
1.方法1.使用jsp實現
jsp中使用<%@page jsp代碼
<%@page errorPage="error/error500.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page errorPage="error/error500.jsp" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>這個頁面有1/0的算術錯誤</h1>
<%System.out.println("=======進入calculationError.jsp=========");%>
<%System.out.println("=======這個頁面有1/0的算術錯誤=========");%>
<%System.out.println(1/0);%>
</body>
</html>
2.方法2在web.xml中配置
xml 配置
<error-page>
<error-code>404</error-code>
<location>/error/notFound404.jsp</location>
</error-page>
二、遇到的問題和解決
1.web.xml相對路徑報錯
解決:
去掉…即可
…可以在href,src中使用
<error-page>
<error-code>404</error-code>
<location>/error/notFound404.jsp</location>
</error-page>