liguofeng29’s blog

個人勉強用ブログだっす。

JSP - exceptionオブジェクト

1.  JSP内のexceptionをキャッチした際のオブジェクトである。

2. <%@ page isErrorPage="true" %>際に使用できる。

 

throwEx.jsp
<%@ page contentType="text/html;charset=Shift_jis" language="java"  errorPage="error.jsp"%>
<html>
<head>
<title>throw a exception</title>
</head>
<body>
<%-- applicationオブジェクトに属性 --%>
<%
int i = 10;
int b = 10 / 0; // エラー発生
%>
</body>
</html>

 

error.jsp
<%@ page contentType="text/html;charset=Shift_jis" language="java"  isErrorPage="true"%>
<html>
<head>
<title>it is a error page.</title>
</head>
<body>
<%-- exceptionオブジェクト --%>
エラークラス = <%=exception.getClass()%><br>
エラーメッセージ = <%=exception.getMessage()%>
</body>
</html>
 

URL:http://localhost:8080/webDemo/throwEx.jsp

error.jspが応答ページとなる。