Search

JSP ์˜ˆ์™ธ ์ฒ˜๋ฆฌ

JSP ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€

์‘๋‹ต ์ƒํƒœ ์—๋Ÿฌ ์ฝ”๋“œ๋ณ„ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€

404 ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ

โ€ข
web.xml
<error-page> <error-code>404</error-code> <location>/error/404.jsp</location> </error-page>
XML
๋ณต์‚ฌ
โ€ข
404.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> <h1>404 ์—๋Ÿฌ ํŽ˜์ด์ง€</h1> <div> <p>ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</p> <h5>์š”์ฒญ ๊ฒฝ๋กœ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.</h5> <div> <a href="<%= request.getContextPath() %>">๋ฉ”์ธ ํ™”๋ฉด</a> </div> </div> </body> </html>
HTML
๋ณต์‚ฌ

500 ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ

โ€ข
web.xml
<error-page> <error-code>500</error-code> <location>/error/500.jsp</location> </error-page>
XML
๋ณต์‚ฌ
โ€ข
500.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> <h1>500 ์—๋Ÿฌ ํŽ˜์ด์ง€</h1> <div> <p>์‹œ์Šคํ…œ ์ผ์‹œ์ ์ธ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.</p> <h5>๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ํ•ด์ฃผ์„ธ์š”</h5> <div> <a href="<%= request.getContextPath() %>">๋ฉ”์ธ ํ™”๋ฉด</a> </div> </div> </body> </html>
HTML
๋ณต์‚ฌ
โ€ข
500 ์—๋Ÿฌ ๋งŒ๋“ค๊ธฐ
โ—ฆ
exception.jsp
โ—ฆ
exception_pro.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>500 ์—๋Ÿฌ ๋งŒ๋“ค๊ธฐ</title> </head> <body> <form action="exception_pro.jsp" method="post"> <p> ์ˆซ์ž1 : <input type="text" name="num1"> <p> ์ˆซ์ž2 : <input type="text" name="num2"> <p> <input type="submit" value="๋‚˜๋ˆ„๊ธฐ"> </form> </body> </html>
HTML
๋ณต์‚ฌ
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>500 ์—๋Ÿฌ ๋งŒ๋“ค๊ธฐ</title> </head> <body> <% String num1 = request.getParameter("num1"); String num2 = request.getParameter("num2"); int a = Integer.parseInt(num1); int b = Integer.parseInt(num2); int c = a / b; out.print(num1 + " / " + num2 + " = " + c); %> </body> </html>
HTML
๋ณต์‚ฌ

์˜ˆ์™ธ ๋ณ„ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ

โ€ข
web.xml
<error-page> <exception-type>java.lang.Exception</exception-type> <location>/error/exception.jsp</location> </error-page>
XML
๋ณต์‚ฌ
โ€ข
exception.jsp
<h1>์˜ˆ์™ธ ์—๋Ÿฌ ํŽ˜์ด์ง€</h1> <h3>์‹œ์Šคํ…œ ์ž‘์—… ์ฒ˜๋ฆฌ ์ค‘ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.</h3> <a href="<%= request.getContextPath() %>">๋ฉ”์ธ ํ™”๋ฉด</a>
XML
๋ณต์‚ฌ