예외 페이지
에러가 나면 에러페이지로 유도해서 사용자에게 친숙한 페이지를 보여주기 위함
404 - url을 찾을 수 없는 경우
500 - 서버측 오류로 인해 페이지가 나타나지 않는 경우 (nullpointexception등등)
200 - 요청 성공
400번대 에러 = 클라이언트측 에러
500번대 에러 = 서버측 에러
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String name = request.getParameter("name"); //null
int a = name.length();
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.box{
height: 100vh;
display : flex;
align-items : center;
justify-content : center;
}
</style>
</head>
<body>
<div class="box">
<div>
<img alt="제목" src="/JSPBasic/html/1.jpg" width="100px">
요청한 페이지를 찾을 수 없습니다
</div>
</div>
</body>
</html>
에러가 나면 위의 에러페이지가 보이는게 아닌 error_view 페이지로 이동시켜서 사용자 친화적인 페이지를 보여줌
<!-- 에러처리 (/errorpage의 error_view.jsp를 보여줌) -->
<error-page>
<error-code>404</error-code>
<location>/errorpage/error_view.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/errorpage/error_view.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/errorpage/error_view.jsp</location>
</error-page>
web.xml에 에러처리구문을 작성해둠
'jsp' 카테고리의 다른 글
2022_12_01 Foward & Redirect 02 (sendRedirect) (0) | 2022.12.01 |
---|---|
2022_12_01 Foward & Redirect 01 (Forward) (0) | 2022.12.01 |
2022_12_01 Path (절대경로 / 상대경로) (1) | 2022.12.01 |
2022_12_01 application 객체 (0) | 2022.12.01 |
2022_11_30 Session Login Practice (세션 로그인 연습) (1) | 2022.11.30 |
댓글