22.5.16
1. web.xml에 처리
- WEB-INF 아래에 있는 web.xml 페이지에 error-page 태그로 오류페이지 호출
- error-code에는 주요 코드 종류 입력(ex) 404 500 503 등등)
- exception-type에는 자바 예외유형의 정규화 클래스 설정에 사용(ex)NullpointException, NumberformatException 등)
- location은 오류 페이지의 URL 설정
실제 태그
<error-page>
<error-code>404</error-code>
<location>/error/exceptionNoPage.jsp</location>
</error-page>
이런식으로 web.xml에 태그를 주면 예외처리가 가능함.
2. try-catch 문 사용
- 자바에서 사용하던 것 처럼, 스크립틀릿(<% %>)태그 안에 try-catch문을 줘서 예외 혹은 에러를 처리할 수 있음
<%
try {
conn = DBconnection.getconnConnection();
String sql = "select * from member_tbl where id = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, id);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
member = new Member(
rs.getInt("id"),
rs.getString("userName"),
rs.getString("email"),
rs.getString("password"));
}
} catch (SQLException e) {
}
%>
이렇게 스크립틀릿 태그 안에 try-catch문을 사용
---
오늘은 여기까지!
35) EL(표현언어) 메소드 호출(JSTL 인코딩 디코딩) (0) | 2022.05.17 |
---|---|
34) 세션 (0) | 2022.05.17 |
32) JTSL 날짜 시간 형식화 및 다국어 처리 (0) | 2022.05.12 |
31) 유효성 검사 (0) | 2022.05.09 |
30) JSTL과 COS 설치법(Convert Maven) (0) | 2022.05.08 |
댓글 영역