728x90
<%@ %>(지시자; Directive)를 이용한 방식
해당 jsp 페이지에서 에러가 발생했을 시 이를 처리할 errorPage를 설정했다.
<body>
<%=10/0 %>
</body>
위의 코드를 작성하여 에러를 유도했다.
클라이언트(웹 브라우저)가 해당 jsp 파일을 웹 서버에게 요청하면, 웹 서버 WAS를 거쳐 해당 페이지를 클라이언트에게 전달한다. 클라이언트가 전달 받은 jsp파일을 실행하여 화면에 결과를 출력한다.
클라이언트가 jsp파일을 실행하던 중 에러(Arithmeticexception / by zero)가 발생하여 quiz5_error.jsp로 이동한다.
web.xml을 이용한 방식
web.xml은jsp나 Servlet을 위한 설정 파일로, 브라우저가 실행될 때 반드시 거치는 파일이다.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
<display-name>jspExam</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
<location>/tag/quiz5_error.jsp</location>
</error-page>
</web-app>
web.xml파일에서 에러 코드와 에러 페이지를 지정했다.
해당 에러 코드가 발생하면 location에 지정된 경로의 파일로 이동한다.
728x90
'Jsp' 카테고리의 다른 글
[jsp 내장 객체] pageContext, request, session, application의 Scope (0) | 2022.05.11 |
---|---|
[jsp] jsp 내장 객체: request (0) | 2022.05.10 |
Form태그(get방식, post방식) (0) | 2022.04.26 |
지시자(Directive), 선언문(Declaration), 스크립트 릿(Scriptlet), 표현식(Expression) (0) | 2022.04.26 |
웹 서버와 WAS(Web Application Server) (0) | 2022.04.25 |