본문 바로가기
IT/JSP

Error page 관리

by dya0 2019. 5. 13.

jsp를 연습하면 400 405 500등 여러 에러를 마주했을 것이다. 

사용자입장에서 404에러가 뜨는 것보다 한글로 출력된 화면을 보는게 편하기 때문에 

에러페이지를 만들어 둬야한다.

각각의 응답 상태 코드별로 보여줄 페이지를 지정한다.  

<error-page>: 하나의 에러페이지를 지정  
<error-code>: 에러 상태 코드 지정  <location>: 에러 페이지의 위치를 지정  

<exception-type>: 예외 종류

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    <error-page>
        <error-code>404</error-code>
        <location>/ch05/error/error404.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/ch05/error/error500.jsp</location>
    </error-page>
    <error-page>
        <error-code>405</error-code>
        <location>/ch05/error/error405.jsp</location>
    </error-page>
    <error-page>
        <exception-type>java.lang.NullPointerException</exception-type>
        <location>/ch05/error/errorNullPointerException.jsp</location>
    </error-page>
 
Colored by Color Scripter

xml 파일에서 제어하기 위해서는 필요한 파일을 지정해야 한다.

1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>404에러</title>
</head>
<body>
<h1>파일을 찾을 수 없습니다. 대소문자 확인 파일 유무 확인해주세요~</h1>
</body>
</html>
Colored by Color Scripter

이와 같이 각각의 파일의 내용을 채워보자

1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>405에러</title>
</head>
<body>
405에러가 발생했습니다.
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter

'IT > JSP' 카테고리의 다른 글

Forward Action 연습 1  (0) 2019.05.14
액션 태그  (0) 2019.05.14
Exception  (0) 2019.05.13
web.xml로 url 제어하기  (0) 2019.05.13
Config vs application  (0) 2019.05.13