Web Programming/JSP

[JSP] 에러 처리

IT수정 2024. 10. 4. 15:56

HTTP 에러 코드

클라이언트와 서버 간의 통신에서 발생하는 문제를 나타내는 상태 코드

 

1xx (정보 응답)

  • 100 Continue: 클라이언트가 요청을 계속 진행할 수 있음을 나타냄.
  • 101 Switching Protocols: 클라이언트가 요청한 프로토콜로 전환하고 있음을 나타냄.

2xx (성공)

  • 200 OK: 요청이 성공적으로 처리됨.
  • 201 Created: 요청이 성공적으로 처리되었으며, 새로운 리소스가 생성됨.
  • 202 Accepted: 요청이 수락되었지만 아직 처리되지 않음.
  • 204 No Content: 요청은 성공적이었지만 반환할 내용이 없음.
  • 205 Reset Content: 요청이 성공적으로 처리되었으며, 클라이언트가 문서 뷰를 리셋해야 함.
  • 206 Partial Content: 서버가 클라이언트의 범위 요청에 대한 일부 콘텐츠를 반환함.

3xx (리다이렉션)

  • 300 Multiple Choices: 요청한 리소스에 여러 가지 선택이 가능함.
  • 301 Moved Permanently: 요청한 리소스가 영구적으로 다른 URI로 이동됨.
  • 302 Found: 요청한 리소스가 임시로 다른 URI로 이동됨.
  • 303 See Other: 요청한 리소스가 다른 URI에서 찾을 수 있음.
  • 304 Not Modified: 요청한 리소스가 수정되지 않음. 클라이언트 캐시 사용 가능.
  • 307 Temporary Redirect: 요청한 리소스가 임시로 다른 URI로 이동되었음을 나타냄.
  • 308 Permanent Redirect: 요청한 리소스가 영구적으로 다른 URI로 이동되었음을 나타냄.

4xx (클라이언트 오류)

  • 400 Bad Request: 잘못된 요청으로 서버가 요청을 이해할 수 없음.
  • 401 Unauthorized: 인증이 필요함. 클라이언트는 인증 정보를 제공해야 함.
  • 403 Forbidden: 서버가 요청을 이해했지만 접근이 거부됨.
  • 404 Not Found: 요청한 리소스를 찾을 수 없음.
  • 405 Method Not Allowed: 요청 메소드가 허용되지 않음.
  • 406 Not Acceptable: 요청한 리소스가 클라이언트의 요구를 만족하지 않음.
  • 408 Request Timeout: 서버가 요청을 기다리는 동안 시간이 초과됨.
  • 409 Conflict: 요청이 현재 상태와 충돌함.
  • 410 Gone: 요청한 리소스가 영구적으로 사라짐.
  • 413 Payload Too Large: 요청한 페이로드가 서버에서 처리할 수 있는 한계를 초과함.
  • 414 URI Too Long: 요청한 URI가 너무 김.
  • 415 Unsupported Media Type: 요청한 미디어 형식이 지원되지 않음.
  • 429 Too Many Requests: 클라이언트가 너무 많은 요청을 보냄.

5xx (서버 오류)

  • 500 Internal Server Error: 서버 내부에서 오류가 발생함.
  • 501 Not Implemented: 요청된 기능이 서버에서 지원되지 않음.
  • 502 Bad Gateway: 서버가 게이트웨이로서 유효하지 않은 응답을 받음.
  • 503 Service Unavailable: 서버가 현재 요청을 처리할 수 없음. 유지 보수 중일 수 있음.
  • 504 Gateway Timeout: 게이트웨이가 상위 서버로부터의 요청을 시간 내에 처리하지 못함.

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">

    <display-name>myapp</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>
    
    <servlet>
        <servlet-name>MyServlet2</servlet-name>
        <servlet-class>ch03.MyServlet2</servlet-class>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>MyServlet2</servlet-name>
        <url-pattern>/myServlet2</url-pattern>
    </servlet-mapping>
    
    <error-page>
        <error-code>404</error-code>
        <location>/error/404code.jsp</location>
    </error-page>
    
    <error-page>
        <error-code>500</error-code>
        <location>/error/500code.jsp</location>
    </error-page>
    
</web-app>

 

404code.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% response.setStatus(HttpServletResponse.SC_OK); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>404에러 페이지</title>
</head>
<body>
	요청하는 페이지는 존재하지 않습니다.
</body>
</html>

 

500code.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% response.setStatus(HttpServletResponse.SC_OK); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>500에러 페이지</title>
</head>
<body>
	서비스 사용에 불편을 끼쳐드려서 대단히 죄송합니다.
	빠른 시일 내에 문제를 처리하겠습니다.
</body>
</html>

 

'Web Programming > JSP' 카테고리의 다른 글

[JSP] 서블릿의 요청 방식  (0) 2024.10.07
[JSP] 서블릿 기초 문법  (1) 2024.10.04
[JSP] 예외 내부 객체  (0) 2024.10.04
[JSP] 서블릿 관련 내부 객체  (0) 2024.10.04
[JSP] 외부 환경 정보 제공 내부 객체  (0) 2024.10.04