WEB/2020_webCamp

JSTL (JSP Standard Tag Library)

HBean_ 2020. 8. 6. 04:03

JSTL : JSP 태그를 단순화한 태그들의 Set

  • 장점

    • 빠른 개발 > jsp를 단순화한 많은 태그 제공

    • 코드 재사용성 > 여러 페이지에서 jspl tag 사용 가능

    • scriplet tag 미사용 

 

  • 5가지 종류
    • Core tag (c) : 변수 지원, url 관리, flow control 관련 태그 
    • Function tag (fn) : 문자열 조정/길이 관련된 태그
    • Formatting tags (fmt) : 메시지, 숫자, 날짜 포맷 관련 태그
    • XML tags (x) : flow control, transformation  관련 태그
    • SQL tags (sql) : SQL 관련 태그

 

JSTL Core Tags List

 

JSTL Functions Description Syntax
c:out 내용 출력한다. <%=...%> tag 와 비슷 <c:out value="${'Welcome to javaTpoint'}"/>  
c:import 페이지 불러오기 <c:import url="URL값" var="변수 명" scope="범위" varReader="변수 명"context="context명" charEncoding="인코딩값">
c:set 변수 설정 <c:set var="변수 명" value="설정값" target="객체" property="값" scope="범위">
c:remove 변수 삭제 <c:remove var="변수 명" scope="범위">
c:catch

예외가 발생했을 때, 해당 예외 정보를 가져온다.

<c:catch var = "변수 명">"예외가 발생하는 지 체크하는 곳"</c:catch>

c:if

조건을 걸어서 조건이 true일때만 내용을 보인다.

<c:choose>
<c:when test="조건"></c:when><c:otherwise></c:otherwise>
</c:choose>

c:choose, c:when, c:otherwise

when은 조건을 맞춰야 내용을 보이고 만약 모든 조건에 false면 otherwise에 해당한다. 이는 if/else문과 비슷하지만 이들은 <c:choose>태그 안에 존재해야 한다.

<c:choose>
<c:when test="조건"></c:when><c:otherwise></c:otherwise>
</c:choose>

c:forEach

기본적인 반복 태그다. (java의 while, do-while, for 과 비슷) 정해진 수만큼 태그 사이의 body content를 반복한다.

<c:forEach items="객체명" begin="시작 인덱스" end="종료 인덱스" step="증감식"var="변수 명" varStatus="상태변수">"body content"</c:forEach>

c:forTokens

주어진 구분자를 통해 토큰으로 분리하고 반복을 통해 토큰들을 출력시킨다.

<c:forTokens items="객체명" delims="구분자" begin="시작 인덱스" end="종료 인덱스" step="증감식" var="변수 명" varStatus="상태변수">

c:param

import' tag's URL이 가지는 파라미터를 넣어준다.

<c:param name="파라미터 이름" value="값">
c:redirect

url을 지정해서 특정 페이지로 넘어간다. context 지정하면 context경로/url경로 형식으로 리다이렉트됨

<c:redirect url="URL 경로" context = "context 경로">

c:url

contextPath를 자동으로 붙여주며 url을 생성

<c:url var="변수 명" scope="범위" value="url경로" context="contextName">

 

 

 

 

 

 

 

 

 

JSTL Tutorial and Examples - javatpoint

JSTL Tutorial with examples on JSTL core tags, function tags, formatting tags, sql tags and miscellaneous tags. It includes c:out, c:import, c:set, c:if, c:when, c:choose, c:redirect, c:catch etc.

www.javatpoint.com