์๋ฌํ์ด์ง๋ฅผ ํ๋๋ง ์ง์ ํด์ค๋ ๋์ง๋ง ์ฌ๋ฌ mainํ์ด์ง์์ ๋ค์ํ ์๋ฌ๊ฐ ๋ฐ์ํ ๋๋ง๋ค ์๋ฌ ํ์ ์ ๋ฐ๋ผ ์๋ก ๋ค๋ฅธ ํน์  ์๋ฌํ์ด์ง๋ฅผ ๋ณด์ฌ์ฃผ๊ณ ์ถ์ ๋๋ ์ด๋ป๊ฒ ํด์ผํ๋๊ฐ?
02errorMain.jsp์ ์ฝ๋๋ด์ฉ
<%@ 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>
</head>
<body>
<%
	String error = request.getParameter("error");
	if(error != null){
		if(error.equals("null")){
			throw new NullPointerException();
		}else if (error.equals("class")){
			throw new ClassCastException();
		}else{
			out.print("์๋ฌx");
		}
	}
%>
</body>
</html>
02errorClassCast.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
ํด๋์ค์ผ์คํธ ์๋ฌํ์ด์ง
<%=exception.getMessage() %>
</body>
</html>
02errorNullPointer.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
๋ํฌ์ธํฐ ์๋ฌํ์ด์ง
<%=exception.getMessage() %>
</body>
</html>
02errorMain.jsp์์ request๊ฐ์ฒด๋ฅผ ์ด์ฉํด์ error์ ํ๋ผ๋ฏธํฐ ๊ฐ์ ๋ฐ์์ ๋ณ์์ ๋์ ํ์ฌ if๋ฌธ์ ํตํด ์๋ฌ์ ์ข ๋ฅ์ ๋ฐ๋ผ ์๋ฌ๋ฅผ ๋ฐ์์ํค๋๋ก ํ์๊ณ , WEB-INF ๋ฐ์ web.xml์ ํด๋น ์ฝ๋๋ฅผ ์ถ๊ฐ ํ์๋ค.
<error-page>
		<exception-type>java.lang.NullPointerException</exception-type>
		<location>/06error/02errorNullPointer.jsp</location> ๋ณด์ฌ์ค jsp์์น
</error-page>
<error-page>
		<exception-type>java.lang.ClassCastException</exception-type>
		<location>/06error/02errorClassCast.jsp</location> ๋ณด์ฌ์ค jsp์์น
</error-page>
์ด์  url์ http://localhost:8080/study/06error/02errorMain.jsp?error=null๋ฅผ ์ ๋ ฅํ๋ฉด 02errorNullPointer.jsp๋ก ์ด๋ํ๊ฒ ๋๋ค.
์๋ฌ ์ํ์ฝ๋
- response๊ฐ ์๋ตํ ๋ ์๋ต๋ฐ๋์ ์ํ์ฝ๋๊ฐ ๊ฐ์ด ์ ๋ฌ๋๋ค.(๋ฐ์ดํฐ์ ํจ๊ป)
 - 200 : ์ ์์ฝ๋, ๋ฌธ์ ์์ ๋ ์ฐ๋ฆฌ์ jsp๋ด์ฉ์ด๋ ๊ฐ์ด ์ ๋ฌ 200์ ์ ์ธํ ๋๋จธ์ง๋ jsp๋ด์ฉ ์์ด์ง๊ณ ์ํ์ฝ๋๋ ์๋ฌ๋ฐ์ดํฐ ์ ๋ฌ
 - 300 : ๋คํธ์์ํฌ, ์์ฒญ์ ๋ณด๊ฐ ๋ณ๊ฒฝ, ์ง์ฐ
 - 400 : 403 ๊ถํ์์ : *404* ์ฐพ์ ์ ์์, not found
 - 500 : *์๋ฒ์๋ฌ* ๊ฐ๋ฐ์๊ฐ ์ฝ๋ฉ์ ์๋ชปํ์ ๋ !
 
์๋ฌํ์ด์ง ์ฐ์ ์์
- pageDirective๋ ์์ฑํ๊ณ web.xml์ exception type, code ์ ๋ถ ์์ ๋
 - 1.errorPage
 - 2.exception type
 - 3.code
 - ๋ณดํต์ code๋ก๋ง ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์
 
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Day04(jsp:include๋์ ํ์ด์งํ ๋น) (0) | 2021.10.07 | 
|---|---|
| Day04(pageModule) (0) | 2021.10.07 | 
| Day04(error) (0) | 2021.10.07 | 
| Day03(ArrayList) (0) | 2021.10.06 | 
| Day03(session) (0) | 2021.10.06 |