-
에러 처리 ( 익셉션 직접 처리하기 )JSP 2023. 3. 21. 12:50
익셉션 처리 예제)
- 다음은 name 파라메터가 주어지지 않아서 오류화면(익셉션)이 뜨는 코드이다.
try-catch 로 익셉션을 처리하자
익셉션 처리 try{ 예외 발생 코드 } catch(Exception ex){ } 에러페이지 지정 <%@ page errorPage = "/error/viewErrorMessage.jsp" %>
응답 상태 코드별로 / 익셉션 타입별로 에러 페이지 지정하기
- Servers 폴더의 web.xml 로 이동한다.
응답 상태 코드별로 에러 페이지 지정 <web-app > <error-page> <error-code>404</error-code> <location>/error/error404.jsp</location> </error-page> </web-app> 익셉션 타입별로 에러 페이지 지정 <web-app > <error-page> <exception-type>404</exception-type> <location>/error/errorNullPointer.jsp</location> </error-page> </web-app>
- web-app 태그 사이에 위의 코드를 넣으면, 404 코드가 발생했을 때 location 의 URL로 이동한다.
'JSP' 카테고리의 다른 글
<jsp:param> 페이지에 파라미터 추가 (0) 2023.03.21 <jsp:include> 액션 태그를 이용한 공통 영역 작성 (0) 2023.03.21 JSP 기본 객체, 속성 사용하기 (0) 2023.03.21 out 기본 객체 (0) 2023.03.21 웹 어플리케이션 배포 ( eclips - tomcat ) (0) 2023.03.21