1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Servletでエラー情報を共通エラーページJSPで表示する方法

Last updated at Posted at 2020-01-13

Servletでエラー情報を共通エラーページJSPで表示する方法

以下を追加する
web.xml
  <error-page>
    <exception-type>javax.servlet.ServletException</exception-type>
    <location>/jsp/error.jsp</location>
  </error-page>
exception.jsp(エラー発生JSP)
<%
request.setAttribute("err", "エラーセット1");
throw new ServletException("エラーセット2");
%>
error.jsp(エラー表示JSP)
<%@ page isErrorPage="true" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>共通エラーページ</title>
</head>
<body>
<p>${err}</p>
<p><%=exception.getMessage()%></p>
</body>
</html>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?