에러페이지

2021. 9. 7. 14:29(구)공부/Spring

728x90

web.xml

	<error-page>
          <error-code>400</error-code>
          <location>/WEB-INF/views/common/errorPage.jsp</location>
 	</error-page>
	<error-page>
          <error-code>404</error-code>
          <location>/WEB-INF/views/common/errorPage.jsp</location>
 	</error-page> 
 	<error-page>
          <error-code>405</error-code>
          <location>/WEB-INF/views/common/errorPage.jsp</location>
 	</error-page>
 	<error-page>
          <error-code>500</error-code>
          <location>/WEB-INF/views/common/errorPage.jsp</location>
 	</error-page>
 	<error-page>
          <error-code>503</error-code>
          <location>/WEB-INF/views/common/errorPage.jsp</location>
 	</error-page>

errorPage.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Error Page</title>
</head>
<body>

	<c:if test="${requestScope['javax.servlet.error.status_code'] == 400}">
		<h1>잘못 된 요청입니다.</h1>    
	</c:if>	
	
	<c:if test="${requestScope['javax.servlet.error.status_code'] == 404}">
		<h1>요청하신 페이지를 찾을 수 없습니다.</h1>    
	</c:if>
	
	<c:if test="${requestScope['javax.servlet.error.status_code'] == 405}">
		<h1>요청된 메소드가 허용되지 않습니다.</h1>    
	</c:if>
	
	<c:if test="${requestScope['javax.servlet.error.status_code'] == 500}">
		<h1>서버에 오류가 발생하여 요청을 수행할 수 없습니다.</h1>
	</c:if>
	
	<c:if test="${requestScope['javax.servlet.error.status_code'] == 503}">
		<h1>서비스를 사용할 수 없습니다.</h1>
	</c:if>
	<h1>5초 후 메인 페이지로 돌아갑니다.</h1>   
	<a href="/">HOME</a>
</body>
<script>
	window.onload = function() {
		setTimeout("startPage()", 5000);
	}
	function startPage() {
		document.location.href = "/";
	}
</script>
</html>
728x90

'(구)공부 > Spring' 카테고리의 다른 글

spring security - 2 (controller, login)  (0) 2021.09.16
spring security - 1 (pom, context, web) xml 설정  (0) 2021.09.13
Spring 유효성 검사 - hibernate  (0) 2021.08.24
파일 업로드  (0) 2021.08.16
lombok  (0) 2021.08.04