JSP - 디렉티브 태그 directive tag

imjingu·2023년 9월 3일
0

개발공부

목록 보기
450/481

디렉티브 태그 directive tag

디렉티브 태그는 JSP 페이지를 어떻게 처리할 것인지를 설정하는 태그.
directive : 형용사. 지시하는
JSP 페이지가 서블릿 프로그램에서 서블릿 클래스로 변환할 때 JSP 페이지와 관련된 정보를 JSP 컨테이너에 지시하는 메시지.
따라서 디렉티브 태그는 JSP 페이지를 수정하여 다시 컴 파일하는 경우에만 역할을 수행하기 때문에 개별 HTML 응답에 특별한 영향을 미치지 않음.

page 디렉티브 테그에 콘텐츠 유형을 마이크로 소프트 워드 문서(application/msword)로 설정하기
1) 콘텐츠 유형을 application/msword로 설정하도록 page 디렉티브 태그의 contentType 속성을 작성

<%@ page contentType="application/msword"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	 Today is: <%=new java.util.Date()%>
</body>
</html>

<%@ page contentType="text/xml; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	<%-- 
	page 디렉티브 태그에 콘텐츠 유형을 XML 문서로 한글 출력 설정하기
	1) 콘텐츠 유형을 text.xml로 설정하고 한글을 출력하기 의한 문자열 세트를 utf-8로 설정하도록
	page 디렉티브 태그의 contentType 속성을 작성
	 --%>
	 <h2>contentType 디렉티브 태그ㄹ4>
	 <h4>charset=UTF-8 : 문자 인코딩</h4>
</body>
</html>

page 디렉티브 태그에 Data 클래스를 이용하여 현재 날짜 출력하기

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	 
	 <%-- java.util.Data 패키지를 사용하기 위해 page 디렉티브 import 속성을 작성 --%>
	 <%@ page import="java.util.Date" %>
	 <%-- 현재 날짜를 출력하도록 표현문 태그를 작성 --%>
	 Today is <%=new Date()%>
</body>
</html>

page 디렉티브 태그에 이동할 특정 오류 페이지 작성하기
1) 변수 str에 값을 저장하고 고정된 값을 출력하도록 스크립틀릿 태그를 작성
2) 오류 부분 확인 후에
3) 현재 JSP 페이지에 오류가 발생하면 오류 페이지로 이동하기 위해 page 디렉티브 태그의 errorPage 속성을 작성
4) page_errorPage_error.jsp 작성

<%@ page contentType="text/html; charset=utf-8"%>
<%@ page errorPage="page_errorPage_error.jsp" %> <%-- 에러 발생시 해당페이지로 이동 --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
	 <%
	 	String str = null;
	 	out.println(str.toString()); // str이 null 이어서 오류 발생
	 %>
</body>
</html>

0개의 댓글