JSPでのページオブジェクトの使用は何ですか?例が必要です。
JSPには、エラーページを指定するオプションがあります ページ属性を使用するJSPごと。ページが例外をスローするたびに、JSPコンテナは自動的にエラーページを呼び出します。
以下は、 main.jspのエラーページを指定する例です。 。エラーページを設定するには、 <%@ page errorPage ="xxx"%>を使用します ディレクティブ。
<%@ page errorPage = "ShowError.jsp" %>
<html>
<head>
<title>Error Handling Example</title>
</head>
<body>
<%
// Throw an exception to invoke the error page
int x = 1;
if (x == 1) {
throw new RuntimeException("Error condition!!!");
}
%>
</body>
</html> ここで、以下に示す1つのエラー処理JSPShowError.jspを記述します。エラー処理ページには、ディレクティブ <%@ page isErrorPage ="true"%>が含まれていることに注意してください。 。このディレクティブにより、JSPコンパイラは例外インスタンス変数を生成します。
<%@ page isErrorPage = "true" %>
<html>
<head>
<title>Show Error Page</title>
</head>
<body>
<h1>Opps...</h1>
<p>Sorry, an error occurred.</p>
<p>Here is the exception stack trace: </p>
<pre><% exception.printStackTrace(response.getWriter()); %></pre>
</body>
</html>