[쉽게 배우는 JSP 웹 프로그래밍] 3장 정리

JSP 페이지에 대한 정보를 설정하는 디렉티브 태그의 개념, 특징, 사용법을 다루었습니다. contentType 속성은 콘텐츠 유형을 설정하며, errorPage 속성은 오류 발생 시 이동할 페이지를 설정합니다. isErrorPage 속성은 현재 페이지가 오류 페이지인지 설정하며, isELIgnored 속성은 표현 언어 사용 여부를 설정합니다. include 디렉티브 태그는 외부 파일의 내용을 포함하며, taglib 디렉티브 태그는 태그 라이브러리를 설정합니다.
Feb 20, 2024
[쉽게 배우는 JSP 웹 프로그래밍] 3장 정리

page_contentType02.jsp

<%-- <%@ page contentType="text/xml; charset=utf-8" %> --%> <%@ page contentType="text/html; charset=utf-8" %> <html> <head> <title>Directives Tag</title> </head> <body> <h2>contentType 디렉티브 태그</h2> <h4>text/html : HTML 출력</h4> <h4>charset=utf-8 : 문자 인코딩</h4> </body> </html>
 

핵심 키워드

  • page 디렉티브 태그는 현재 JSP 페이지에 대한 정보를 설정하는 태그다.
  • contentType 속성은 현재 JSP 페이지의 콘텐츠 유형(MIME-type)을 설정하는데 사용한다.
    • 콘텐츠 유형은 주로 text/html, text/xml, text/plain 등이며, 기본 값은 text/html 이다.
 

page_errorPage.jsp

<%@ page errorPage="page_errorpage_error.jsp" %> <html> <head> <title>Directives Tag</title> </head> <body> <% String str = null; out.println(str.toString());%> </body> </html>

page_errorPage_error.jsp

<%@ page contentType="text/html; charset=utf-8" %> <%@ page isErrorPage="true" %> <html> <head> <title>Directives Tag</title> </head> <body> <h4>errorPage 디렉티브 태그</h4> 에러가 발생했습니다. <% exception.printStackTrace(new java.io.PrintWriter(out)); %> </body> </html>
 

핵심 키워드

  • errorPage 속성은 현재 JSP 페이지가 실행되는 동안 오류가 발생하면 특정 오류 페이지로 이동하는 데 사용한다.
    • 웹 서버가 제공하는 기본 오류 페이지를 사용하지 않고 이동할 오류 페이지의 URL을 설정한다.
  • isErrorPage 속성은 현재 JSP 페이지가 오류 페이지인지 여부를 설정하는 데 사용한다.
    • 기본값은 false이며 예외 처리를 위한 내장 객체인 exception 변수를 사용할 수 없다. 속성값을 true로 설정하면 현재 JSp 페이지는 오류 페이지가 된다.
    • 만약 다른 JSP 페이지에서 오류가 발생하면, 호출되는 오류 페이지는 true가 설정된 JSP 페이지가 된다.
 

page_isELIgnored.jsp

<%@ page contentType="text/html; charset=utf-8" %> <%@ page isELIgnored="true" %> <html> <head> <title>Directives Tag</title> </head> <body> <% request.setAttribute("RequestAttribute","request 내장 객체"); %> ${requestScope.RequestAttribute} </body> </html>
 

핵심 키워드

  • isELIgnored 속성은 현재 JSP 페이지의 표현 언어(expression language) 사용 여부를 설정하는 데 사용한다. 기본 값은 false이며 JSP 페이지에 표현 언어의 표현식 ${}를 사용할 수 있다.
    • 속성값을 true로 설정하면 JSP 페이지에 사용된 표현 언어ㅓ의 표현식을 처리할 수 없기 때문에 정적 텍스트로 처리된다.
 

include01.jsp

<%@ page contentType="text/html; charset=utf-8" %> <html> <head> <title>Directives Tag</title> </head> <body> <%@include file="include01_header.jsp" %> <h4>--------현재 페이지 영역--------</h4> </body> </html>

include01_header.jsp

<%@ page contentType="text/html; charset=utf-8" %> <html> <head> <title>Directives Tag</title> </head> <body> <h4>헤더 페이지 영역입니다.</h4> </body> </html>
 

핵심 키워드

  • include 디렉티브 태그는 현재 JSP 페이지의 특정 영역에서 외부 파일의 내용을 포함하는 태그다. 현재 JSP 페이지에 포함할 수 있는 외부 파일은 HTML, JSP, 텍스트 파일 등이다.
    • include 디렉티브 태그는 JSP 페이지 어디에서든 선언할 수 있다.
 

taglib.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <html> <head> <title>Directives Tag</title> </head> <body> <c:forEach var="k" begin="1" end="10" step="1"> <c:out value="${k}" /> </c:forEach> </body> </html>
 

핵심 키워드

  • taglib 디렉티브 태그는 현재 JSP 페이지에 표현 언어, JSTL, 사용자 정의 태그 등 태그 라이브러리를 설정하는 태그다.
    • taglib 디렉시브 태그가 서블릿 프로그램으로 번역될 떄 uri 속성 값은 JSP 컨테이너에 사용자가 정의한 태그 라이브러리의 위치를 알려준다. prefix 속성 값은 사용자가 정의한 태그 라이브러리의 접두어 태그가 무엇인지 JSP 컨테이너에 알려주는 역할을 한다.
 

결론

해당 코드들을 작성하면서 디렉티브 태그의 개념과 특징, 디렉티브 태그 구성 요소의 사용법을 익힐 수 있었다.
Share article

More articles

See more posts
RSSPowered by inblog