[JSP] web.xml - <error-page> 에러에 페이지 설정

Posted at 2009/06/30 20:44 // in 웹프로그래밍™/JSP,JAVA // by 블루비
JSP 에서 HTTP 에러 페이지를 설정을 위한 설정 입니다.

/WEB-INF/web.xml 파일에 다음과 같이 추가

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>http://blueb.net/blog</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</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>




code404.jsp , code500.jsp 페이지를 /error 디렉토리에서 생성합니다.


code404.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
response.setStatus(HttpServletResponse.SC_OK);
%>
<html>
<head>
<title>404 Not Found</title>
</head>
<body>The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. </body>
</html>


code500.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
response.setStatus(HttpServletResponse.SC_OK);
%>
<html>
<head>
<title>500 Internal Server Error</title>
</head>
<body>
The server encountered an unexpected condition which prevented it from fulfilling the request.
</body>
</html>


셋팅이 끝났다면

WAS 엔진을 제 가동합니다.

2009/06/30 20:44 2009/06/30 20:44

http://blueb.net/blog/trackback/1432

댓글을 남겨주세요.

[로그인][오픈아이디란?]