예외
- 예외가 발생하면 톰캣이 Request에 Throwable 객체에 담아 에러페이지에 전달
- 상위 객체인 Throwable로 처리할수도 있고, 예외타입에 따라 분기할 수도 있음.
에러발생!
Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception");
Integer statusCode = (Integer)req.getAttribute("javax.servlet.error.status.code");
String servletName = (String) req.getAttribute("javax.servlet.error.servlet_name");
String requestUri =(String) getAttribute("javax.servlet.error.request_uri");
web.xml
예외페이지 설정_servlet
<servlet>
<servlet-name>ErrorHandler</servlet-name>
<servlet-class>kr.or.ddit.basic.T04_ErrorHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ErrorHandler</servlet-name>
<url-pattern>/ErrorHandler</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/ErrorHandler</location>
</error-page>
에러페이지 세팅_jsp
<error-page>
<error-code>404</error-code>
<location>/error/error404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/error500.jsp</location>
</error-page>
참고