1. error 500 발생시키기
- add_result.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>
<%
int num = Integer.parseInt(request.getParameter("num"));
int sum = 0;
for(int i = 1 ; i <= num ; i++) {
sum += i;
}
%>
<h1>1부터 <%=num %>까지의 합계는 <%=sum %>입니다.</h1>
</body>
</html>
2. error.jsp 생성하여 예외처리하기
- error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
→ isErrorPage="true"를 추가해야 exception 객체를 볼 수 있다.
<%@page import="java.io.PrintWriter"%>
<%@ 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>
<h1>에러발생!! <%=exception.getMessage() %></h1>
<%
PrintWriter pw = response.getWriter();
exception.printStackTrace(pw);
%>
</body>
</html>