728x90
반응형
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<%-- isErrorPage="true" : 현재 페이지가 오류 페이지임. exception 객체 제공 --%>
<%-- src/main/webapp/ch07/error.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>오류페이지</title>
</head>
<body>
<h1>파라미터 name을 입력해주세요.</h1>
<h1>계속 오류시 전산부로 전화요망</h1>
<h1>담당자:홍길동, 전화:1234</h1>
<%= exception.getClass().getName() %>
<% exception.printStackTrace(response.getWriter()); %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- src/main/webapp/ch07/error404.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>요청 페이지 없음</title>
</head>
<body>
<h1>요청하신 페이지는 존재하지 않습니다.</h1>
<h2>URL 주소가 올바른지 확인해 주세요</h2>
<h3>요청 URL : <%=request.getRequestURI() %></h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- src/main/webapp/ch07/error500.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>요청페이지 요류 발생</title>
</head>
<body>
<h1>요청하신 페이지에서 오류가 발생했습니다.</h1>
<h1>전산부로 연락주세요. 홍길동, 전화:1234</h1>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page errorPage="error.jsp" %>
<%-- src/main/webapp/ch07/errorForm1.jsp : 예외 발생 페이지 --%>
<%-- errorPage 속성 : 현재 페이지에서 오류 발생하면 error.jsp 호출 등록 --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>예외 발생 페이지</title>
</head>
<body>
<%=request.getParameter("name").trim() %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- src/main/webapp/ch07/errorForm2.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
결과1 : <%=100/10 %><br>
결과2 : <%=Integer.parseInt("abc") %><br>
<%--
error 페이지 처리
1. 해당페이지별로 오류페이지 설정
<%@ page errorPage="xx.jsp" %>
2. web.xml에 예외 클래스별로 설정
<error-page>
<exception-type>...
3. web.xml에 오류코드별로 설정
<error-page>
<error-code>500...
4. 웹컨테이너에서 기본으로 제공하는 에러페이지
--%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- src/main/webapp/ch07/errorNumber.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>숫자만 입력하세요</h1>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>jsp2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
<!-- error 페이지 설정 -->
<error-page>
<!-- 404 코드 오류 : 해당 페이지 없음. -->
<error-code>404</error-code>
<location>/ch07/error404.jsp</location>
</error-page>
<error-page>
<!-- 500 코드 오류 : 해당 페이지에 오류가 있음 -->
<error-code>500</error-code>
<location>/ch07/error500.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/ch07/errorNumber.jsp</location>
</error-page>
</web-app>
728x90
반응형