갈림길 이정표

[JSP] 페이지 지시어 / HTTP 코드 오류창 변경 본문

Programming Language/Servlet & JSP

[JSP] 페이지 지시어 / HTTP 코드 오류창 변경

이몽뇽 2020. 8. 25. 20:02

HTTP 상태 500 Error: 원래 웹페이지의 서버 쪽 소스에 이상이 생겼을 때 나타나는 현상

대부분 사람들이 느껴봤겠지만 인터넷을 이용하다가 이런 오류 페이지를 만나면 당황할 수 밖에 없다. (최근에는 각 회사별로 오류 페이지에 대한 조치를 취하기 때문에 그 사이트가 없어지지 않는 이상 자주 보진 못했던 거 같다.)

오류 페이지가 뜨면 Client입장에서는 매우 당황 스럽고 짜증이 날 수 있기 때문에 웹 서버 관리자는 HTTP 오류 페이지에 대한 조취를 취하여 사용자들의 자연스러운 인터넷 이용 경험 환경을 주는 것이 좋다.

 

이러한 HTTP 오류 페이지에 대응하기 위한 해결방법을 알아보도록 하자 (HTTP 오류 페이지 종류)

 

 

에러 메세지 페이지 변경 방법

  1. JSP페이지 지시어 errPage="에러페이지.jsp" 추가 후,
    에러페이지.jsp파일 페이지 지시어에 isErrorPage="true"(에러페이지 발생시 보여주는 화면임을 알림) 추가
  2. web.xml에 <error-page></error-page> tag 추가

<%= 10 / 2 %> 일 때

 

<%= 10 / 0 %> 일 때

더보기
  • session="true"
  • buffer="8kb"
  • autoFlush="true"
  • isThreadSafe="true"
[jspStart2.jsp]

<!--일반적으로 지시어는 문서의 상단에 기술, 지시어 전에는 어떤 내용도 적지 않는다. --%>

<!--페이지 지시어 -->
<%--페이지 지시어 안에는 주석 처리 불가 --%>
<%@ page	
	language="java"
	contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.util.Date"
%>
<!-- 분리 가능 -->

<!-- 다음 페이지 지시어는 기본값이므로 생략가능(쓰지 않아도 적용되는 것들) -->
<%@	page
	import="java.lang.*"
	session="true"
	buffer="8kb"
	autoFlush="true"
	isThreadSafe="true"
	
	info="jsp만세"
	errorPage="myerr.jsp"
%>
<%--errorPage 는 forward방식 --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>페이지 지시어 이해</title>
</head>
<body>
페이지 지시어 이해
<br>
<%= new Date() %>
<br>
<%= this.getServletInfo() %>	<!-- this: 페이지 지시어에 있는 정보 -->
<br>
<%= 10 / 0 %>	<!-- 10 / 0 ⇒ err.500내부 오류(연산 불가) -->
		<!-- but 클라이언트 에 500 err출력하면 당황할 수 있으므로 페이지 지시어에errPage설정해놓는게 좋음-->


</body>
</html>
[myerr.jsp]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    isErrorPage="true"
%>
<!-- isErrorPage="true": err가 났을 때 대체해서 보여줄 jsp파일 입니다. 라고 선언 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Foward (주소가 바뀌지 않음)</title>
</head>
<body>
삐빅 - 에러났습니다.
<%= exception.getMessage() %>	<!-- 에러 원인 -->
</body>
</html>
더보기
[web.xml]

<?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" id="WebApp_ID" version="4.0">
  <display-name>web_pro4</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>/error.jsp</location>
  </error-page>
   -->
</web-app>
Comments