6. 에러 페이지 세팅
웹 어플리케이션 실행 도중에 발생할 수 있는 오류에 대비한
예외 처리 코드를 작성하여 비정상적인 종료를 막기 위한 세팅

1) 웹 에러
개발자의 실수로 일어날 수 있는 웹 에러 두 가지
404 : Not Found Error : 요청경로 오류, 잘못된 url로 요청/
500 : Internal Server Error : 요청 페이지의 로직 오류 (자바 문법 오류)

그 외 HTTP 상태코드
[2xx] Success 성공 관련 코드
200 : 성공 : 서바가 요청한 페이지를 잘 처리 제공했다.
201 : created : 서버에 요청한대로 데이터가 생성되어 제공되었다.

 

[3xx] Redirection 이동관련 코드

 

[4xx] Client Error 관련 코드
400 : Bad Request : 요청이 이상함. 
405 : Method Not Allowed : 요청해 실행되어야할 메서드가 안된다. 허용되지않는다.

 

[5xx] Server Error 관련 코드
503 : Service Unavailable : 서비스 지원불가(웹은 살아있는데 서버가 죽었을때)

2) 예외 처리 방법
- try/catch/finally 를 이용 : 자바 언어에서 예외처리 구문 이용
- page 디렉티브태그 이용한 예외처리 : errorPage="erorr.jsp" isErrorPage="true"
- web.xml에 예외처리 : <error-page>태그와 하위태그 이용

* 동시 적용시 예외처리 우선순위
1. try/catch/finally
2. page 디렉티브 태그
3. web.xml
4. 위 항목에 해당안되면 웹서버에서 제공하는 기본 오류페이지 출력

3) web.xml에 예외처리

<error-page>
<error-code>...</error-code> 또는 <exception-type>...</exception-type>
<location>...</location>
</error-page>

error-code : 오류 코드 설정
exception - type : 자바예외 유형의 클래스 이름 설정
location : 에러페이지에 URL 설정

 

<?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">

	
	<!-- 에러페이지 세팅 -->
	<!-- <error-page>
		<error-code>500</error-code>
		<location>/jsp02/errorXml.jsp</location>
	
	</error-page> -->
<!-- 	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/jsp02/errorXml.jsp</location>
	
	</error-page> -->
</web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>errorXml</title>
</head>
<body>
	<h1>공사중입니다</h1>
</body>
</html>

+ Recent posts