본문 바로가기
카테고리 없음

web.xml를 통해서 HTTP오류처리(기본 에러페이지 처리)

by 미눅스[멘토] 2023. 8. 11.
728x90

web.xml에 코드작성

	<!-- 기본 에러 페이지 설정 시작 
	웹 컨테이너(tomcat서버) 설정 파일(web.xml)의
	-->
	<error-page>
		<location>/error/errorDefault</location>
	</error-page>
	
	<!-- 기본 에러 페이지 설정 끝-->

 

 

Controller에 요청 메소드 작성

	//요청URI : /error/errorDefault
	@GetMapping("/error/errorDefault")
	public String errorDefault() {
		//forwarding
		return "error/errorDefault";
	}

 

그리고 Controller에 맞는 패키지 및  jsp생성

 

 

 

jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<section class="content">
	<div class="error-page">
		<h2 class="headline text-danger">Default Error</h2>
		<div class="error-content">
			<h3>
				<i class="fas fa-exclamation-triangle text-danger"></i> Oops!
				Something went wrong.
			</h3>
			<p>
				We will work on fixing that right away. Meanwhile, you may <a
					href="/">return to dashboard</a> or try using the
				search form.
			</p>
		</div>
	</div>
</section>

 

 

예외타입을 사용한 에러를 제외한 나머지를 

여기서 처리한다