티스토리 뷰
web.xml 파일을 통한 에러 페이지 지정
Servlet 또는 JSP에서 catch 하지 않은 Exception 또는 HTTP Error를 처리할 페이지를 지정함
web.xml 페이지를 이용하여 에러 페이지를 지정할 수 있음.
$CATALINA_HOME/conf/web.xml은Tomcat 서버전체에대한에러페이지설정가능
- 에러페이지(location)는webapps/ROOT를기준으로경로지정
ContextRoot/WEB-INF/web.xml은응용별로에러페이지설정가능
- 에러페이지는ContextRoot를기준으로경로지정
실습 필요 사항 :
1. generror.jsp
2. process_error.jsp
3. ContextRoot/WEB-LNF/web.xml
generror.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> <%= 1/0 %> </body> </html> | cs |
process_error.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page isErrorPage="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> <table border = 5 align="center"> <tr><th class="title"> Error </table> <P> Following error found: <I><%= exception %></I>. Stack Trace: <PRE> <%@ page import="java.io.*" %> <% exception.printStackTrace(new PrintWriter(out)); %> </PRE> </body> </html> | cs |
web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Idbclass</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> <exception-type>java.lang.ArithmeticException</exception-type> <location>/process_error.jsp</location> </error-page> </web-app> | cs |
'4학년 1학기 > JavaScript' 카테고리의 다른 글
JSP와 Servlet의 차이 (0) | 2017.04.27 |
---|---|
JAVA_BEAN (1) | 2017.04.13 |
servlet (0) | 2017.04.12 |
"starting tomcat v7.0 server at localhost has encountered a problem" (0) | 2017.04.01 |
[Servlet] User-Agent로 웹브라우저 종류 판단 (0) | 2017.03.23 |