개발자의 길/JSP
JSP 에러 페이지 처리
모쿠
2017. 4. 12. 14:35
<Directive를 사용한 에러 페이지 처리>
- JSP를 실행하는 도중에 Exception이 발생하면 errorPage 속성에 지정된 페이지로 이동
<02_errorPage.html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page errorPage="error.jsp" %> <%-- JSP를 실행하는 도중에 Exception이 발생하면 errorPage 속성에 지정된 페이지로 이동 --%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JSP</title> </head> <body> <h1>Directive를 사용한 에러 페이지 처리</h1> <p> 나눗셈 결과: <%=(123/0)%></p> </body> </html> | cs |
<출력화면>
<03_errorPage.html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JSP</title> </head> <body> <h1>배포 관리자(web.xml)을 사용한 에러 페이지 처리</h1> <a href="none.jsp">파일이 없는 링크(404 에러)</a> <p>계산 결과: <%=(123/0) %></p> </body> </html> | cs |
<web.xml>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?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_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>WEB07_JSP1</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <error-page> <error-code>404</error-code> <location>/error/code404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error/code500.jsp</location> </error-page> </web-app> | cs |
<츨력화면>