우리는 평소에 URL을 잘못입력하면
이러한 페이지를 맞닥들인다.
흔한 에러인 404라는 경로에러이다.
error에 관한 내용은 저번에 올렸던 글을 참조 바란다.
https://lcm9243.tistory.com/48
Tomcat Error Code
우리가 JSP를 공부하면서 예외가 발생하는 경우가 많다. 이런식으로 말이다. 톰캣을 만져보면 404에러는 가장 흔히 보이는 에러일 것이다. 지정된 URL을 처리하기 위한 자원이 존재하지 않는다는
lcm9243.tistory.com
이번 시간에는 내 마음대로 에러페이지를 설정을 해보았다.
간단히 두 가지 페이지를 만들어보았다. 404버튼을 누르게되면 404에러페이지로 가지않고 내가 만든페이지로 가게끔, 500버튼을 누르게되면 500에러페이지로 가지않고 내가 만든페이지로 가게끔 말이다.
버튼 클릭시 말고도 해당 오류가 생기면 내가만든 페이지가 나타난다.
error.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>에러페이지 확인해보기</title>
</head>
<body>
<div align="center">
<h2>
<button type="button" onclick="location.href='404page.jsp'">404</button>
<button type="button" onclick="location.href='500page.jsp'">500</button>
</h2>
</div>
</body>
</html>
web.xml
<error-page>
<error-code>404</error-code>
<location>/404page.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/500page.jsp</location>
</error-page>
404page.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% response.setStatus(HttpServletResponse.SC_OK); %>
<html>
<head>
<title>ZeroLab</title>
</head>
<body>
<br><br><br>
<h1 align="center">404 <br><br> 지정된 URL을 처리하기 위한 자원이 존재하지 않음.<br> (페이지가 없음)<br> 요청하신 페이지가 있는지 확인해주세요.</h1>
</body>
</html>
500page.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% response.setStatus(HttpServletResponse.SC_OK); %>
<html>
<head>
<title>ZeroLab</title>
</head>
<body>
<br><br><br>
<h1 align="center">500 <br><br>서버 내부 에러.<br> (JSP에서 예외가 발생하는 경우)<br>서버를 확인해주세요</h1>
</body>
</html>
'JSP' 카테고리의 다른 글
Forward action tag를 이용한 데이터 출력 (페이지 4개) (1) | 2022.09.20 |
---|---|
현재시간 + 구구단 (1) | 2022.09.19 |
Servlet GET, POST 한글 처리 방법(Encoding) (0) | 2022.09.18 |
JSP 4가지 Scope (0) | 2022.09.18 |
Servlet 계산기 (2) | 2022.09.16 |