일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- JAVA #JSP #Servlet #Exception #custom #익셉션 #에러처리 #에러
- #JSP #Servlet #제이에스피 #서블릿 #필터 #filter #web.xml #필터예제 #filter예제
- Listener #jsp #servlet #ServletContextListener #리스너
- #JSP #Servlet #제이에스피 #서블릿 #세션 #session #세션로그인 #세션예제
- #JSP #Servlet #세션 #Session #제이에스피 #서블릿
- #JAVA #정보은닉 #접근제어자 #private
- #JSP #Servlet #세션 #Session #제이에스피 #서블릿 #web.xml #세션알림 #알림팝업 #세션알림팝업 #session-timeout
- #깃 #Git #Git cherry-pick #체리픽 #깃 체리픽
- #.war #Export
- #JSP #Servlet #@WebServlet #urlPatterns
- JSP #Servlet #Exception #error #page #errorpage #exceptionPage #Customerror #톰캣 #404 #에러페이지 #java
- #Servlet #servletClass #servletURL #servlet구현 #JSP
- #JSP #Servlet #Exception #errorPage #web.xml #error-page #error-code #에러 #익셉션 #java
- #JSP #Servlet #서블릿 #쿠키 #cookie #Cookie #쿠키클래스 #쿠키유틸클래스 #cookieClass #cookieUtilClass #Cookie #제이에스피
- #게터 #세터
- #JSP #Servlet #제이에스피 #서블릿 #필터 #Filter @WebFilter #어노테이션필터
- #유틸클래스 #VO
- Git #Stash #깃 #스테시 #임시저장 #소스트리 #협업툴
- #JSP #Servlet #Ajax #에이젝스 #HTML #success #.HTML() #HTML로붙이기
- #Git #Git Merge #깃 병합
- JSP #Servlet #Exception #errorPage #web.xml #error-page #error-code #에러 #익셉션 #java
- #JSP #Servlet #contextroot #contentdirectory
- Today
- Total
David의 블로그
[JSP/Servlet] Custom Error페이지 만들기3 본문
전시간에는 web.xml에서 error코드별로 에러페이지를 설정하는 방법을 배웠었다.
https://78alswo.tistory.com/12
이번에는
3. web.xml Exception 타입별로 에러페이지 등록방법을 알아보겠다.
[ 3. web.xml Exception 타입별로 에러페이지 만들기]
[web.xml]
JSP/Servlet에서 Exception 타입별로 에러페이지를 등록할 수 있다.
1
2
3
4
5
|
<!-- 익셉션 타입별로 에러페이지 지정하는 방식. -->
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error/errorNullPointer.jsp</location>
</error-page>
|
cs |
<error-page>는 하나의 Exception타입을 지정할 수 있다.
<exception-type>에는 에러페이지로 등록할 Exception 타입을 써주면 되고,
<location>은 지정한 Exception났을 때, 보여줄 에러페이지 경로를 써주면 된다.
[error/errorNullPointer.jsp]
1
2
3
4
5
6
7
8
9
10
|
<%@ page contentType = "text/html; charset=utf-8" %>
<html>
<head><title>NULL 에러 발생</title></head>
<body>
<strong>서비스 처리 과정에서 널(NULL) 에러가 발생하였습니다.</strong>
</body>
</html>
|
cs |
[readParameter2.jsp]
1
2
3
4
5
6
7
8
9
|
<%@ page contentType = "text/html; charset=utf-8" %>
<html>
<head><title>파라미터 출력</title></head>
<body>
name 파라미터 값: <%= request.getParameter("name").toUpperCase() %>
</body>
</html>
|
cs |
URL요청시 name값을 받도록 설정했다.
name값이 없다면, NullPointerException이 발생 할 것이다.
[결과]
readParameter2.jsp에서 name값을 받도록 설정했는데,
name값이 없어서 NullpointerException발생,
에러페이지로 등록한 error/errorNullPointer.jsp화면이 출력된 것을 볼 수 있다.
[소감 및 마무리]
실무에서 빠르게 빠르게 개발을 해야 하다 보니 Exception처리에 대한 중요도를 인지하지 못 했었다.
개발해야 하는 화면들이 많다 보니 신경 못 썼고, 화면마다 최소로 요구하는 기능만 만족하면 됐었기에 크게 신경을 안썼다.
이번 기회로 상황별로 에러페이지를 만드는 방법을 알 수 있었다.
다음 실무나 사이드 프로젝트 때는 예상 가능한 Exception처리를 통하여 다양하게 적용해 봐야겠다.
'프로그래밍 > Jsp_Servlet' 카테고리의 다른 글
[JSP/Servlet]정보를 저장할 수 있는 객체 쿠키.Cookie (1) | 2024.01.06 |
---|---|
[JSP/Servlet]Listener 리스너 (2) | 2023.12.19 |
[JSP/Servlet] Custom Error페이지 만들기2 (0) | 2023.12.02 |
[JSP/Servlet] Custom Error페이지 만들기1 (2) | 2023.12.02 |
[JSP/Servlet]Custom Exception 만들어보기 (1) | 2023.11.26 |