@634

JSP

Advertisement

exceptionオブジェクト

java.lang.Throwable のオブジェクト。
例外発生時に使用。

exceptionオブジェクトの利用

exception.jsp -> pageディレクティブのerrorPageにerror.jspを指定
<%@ page contentType="text/html; charset=Shift_JIS" %>
<%@ page errorPage="error.jsp" %>
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS">
<html lang="ja">
<head>
<title>test</title>
</head>
<body>

<h1>テスト:exception</h1>

<%
    String str = "test";
%>

<p>
<%= Integer.parseInt(str) %>
</p>

</body>
</html>
error.jsp -> pageディレクティブのisErrorPageをtrueに設定
<%@ page contentType="text/html; charset=Shift_JIS" %>
<%@ page isErrorPage="true" %>
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS">
<html lang="ja">
<head>
<title>error</title>
</head>
<body>

<h1>エラー発生</h1>

<p>
<%= exception.getMessage() %>
</p>

</body>
</html>
実行結果
エラー発生

For input string: "test" 

Advertisement

ショートカット

634
634ブログ
このカテゴリのトップページに戻る
Incubator(Pukiwiki)
634ラボ
   UIコレクションギャラリー
   ZO-3ジェネレーター

サイト検索


Y!ログール