JSPエラーページ処理の2つの方法
JSP :
1( , ):
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- , error.jsp--%>
<%@ page errorPage="/demo4/error.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>
<!-- -->
<%
int d = 1/0;
%>
</body>
</html>
エラーページの処理
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- , exception --%>
<%@page isErrorPage="true" %>
<!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>
<!-- -->
<h4> , , !</h4>
<h5> :<%=exception.getMessage() %></h5>
</body>
</html>
方法2:
Webを設定します.xmlグローバルファイル
定義404にページおよび500サーバ内部エラーページが存在しない場合
<%@ 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">
<meta content="3;url=/day08/index.jsp" http-equiv="refresh">
<title>Insert title here</title>
</head>
<body>
<h1> , , 3 !</h1>
</body>
</html>
<%@ 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> , , !</h1>
</body>
</html>
web.xml設定
<error-page>
<error-code>500</error-code>
<location>/demo5/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/demo5/404.jsp</location>
</error-page>