2. Core Tag

core 태그를 사용하기 위해서 페이지 상단에 다음과 같이 선언되어야 된다.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

기능태그prefix
EL 지원catch , out , remove , setc
흐름 제어choose (when , otherwise) , forEach , forTokens , ifc
URL 관리Import (param) , redirect (param) , url (param)c

2.1 <c:out/>

출력 역할

<c:out value="expression" default="expression" escapeXml="boolean"/>

2.2 <c:set/>, <c:remove/>

변수 선언 및 제거 역할

<c:set var="name" scope="scope" value="expression"/>
<c:removevar="name" scope="scope"/>

<c:set var="timezone" scope=="session">
   <c:out value="${cookie['tzPref'].value}" default=="CST"/>
</c:set>

동적 데이터를 단순하게 하는 것 외에도 디폴트 값을 지정하는 <c:out>의 기능은 <c:set>을 통해 변수 값을 설정할 때에도 유용하다.

2.3 <c:catch/>

body에서 실행되는 코드의 예외를 잡아내는 역할

c:catch var="name">
body content
/c:catch>

2.4 <c:if/>

간단한 조건 제어

c:if test="expression" var="name" scope="scope">
body content
/c:if>

2.5 <c:choose/>, <c:when/>, <c:otherwise/>

java의 swith문과 같지만 조건에 문자열 비교도 가능하고 쓰임의 범위가 넓다.
<c:if/>문에 else 가 없기 때문에 이의 대체 기능도 수행한다.

<c:choose>
<c:when test="expression">
body content
</c:when>
...
<c:otherwise>
body content
</c:otherwise>
</c:choose>

<% response.setContentType("text/html"); %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

<h3>조건</h3>
파라메터 없음:<c:out value="${empty param.name}" />

<h4>&lt;c:if test=""></h4>

<c:if test="${empty param.name}">
<form>
이름을 적어주세요.<br>
    <input type="text" name="name">
    <input type="submit" value="확인">
</form>
</c:if>

<c:if test="${!empty param.name}">
    안녕하세요. <c:out value="${param.name}"/>님.
</c:if>

<h4>&lt;c:choose> &ltc:when test=""> &ltc:otherwise></h4>

<c:choose>
    <c:when test="${empty param.name}">
        <form>
        이름을 적어주세요.<br>
            <input type="text" name="name">
            <input type="submit" value="확인">
        </form>
    </c:when>
    <c:when test="${param.name=='admin'}">
        안녕하세요. 관리자님.
    </c:when>
    <c:otherwise>
        안녕하세요. <c:out value="${param.name}"/>님.
    </c:otherwise>
</c:choose>

2.6 <c:forEach/>, <c:forTokens/>

정수 범위내의 반복(java의 for문)과 컬렉션내의 반복(java의 Iterator와 Enumeration 클래스) 지원

<c:forEach/> Syntax

컬렉션내의 반복
<c:forEach [WEBSTUDY:var="varName"] items="collection"
[WEBSTUDY:varStatus="varStatusName"]
[WEBSTUDY:begin="begin"] [WEBSTUDY:end="end"] [WEBSTUDY:step="step"]>
body content
</c:forEach>
정수 범위내의 반복
<c:forEach [WEBSTUDY:var="varName"]
[WEBSTUDY:varStatus="varStatusName"]
begin="begin" end="end" [WEBSTUDY:step="step"]>
body content
</c:forEach>

<c:forTokens/> Syntax

<c:forTokens items="stringOfTokens" delims="delimiters"
[WEBSTUDY:var="varName"]
[WEBSTUDY:varStatus="varStatusName"]
[WEBSTUDY:begin="begin"] [WEBSTUDY:end="end"] [WEBSTUDY:step="step"]>
body content
</c:forEach>

2.7 <c:import/>

웹 어플리케이션 내부의 자원 접근, HTTP, FTP 같은 외부에 있는 자원도 가져와 페이지 내에 귀속시킴.

<c:import url="url" [WEBSTUDY:context="context"]
[WEBSTUDY:var="varName"] [scope="{page\
WEBSTUDY:request|session|application}"]
[WEBSTUDY:charEncoding="charEncoding"]>
<c:param> 서브 태그 위치
</c:import>

2.8 <c:url/>

컨텍스트를 자동으로 추가해서 주소를 자동으로 생성.

<c:url value="value" [WEBSTUDY:context="context"]
[WEBSTUDY:var="varName"] [scope="{page\
WEBSTUDY:request|session|application}"]>
<c:param> 서브태그
</c:url>

2.9 <c:redirect/>

response.sendRedirect() 를 대체하는 태그.

<c:redirect url="value" [WEBSTUDY:context="context"]/>
<c:param> 서브태그
</c:redirect>

<c:catch var="exception">
    <c:import url="ftp://ftp.example.com/package/README"/>
</c:catch>
<c:if test="${not empty exception}">
    <c:redirect url="/errors/remote.jsp"/>
</c:if>

2.10 <c:param/>

문서에 대하여