WEB

JSTL

Daniel_p 2020. 12. 23. 19:55

JSTL(JSP Standard Tag Library) - 태그 형식으로 반복문, 조건문 등을 사용 할 수 있게 해줌.

 

사용하기 위한 준비

1. tomcat.apache.org/download-taglibs.cgi 에 서 .jar 파일을 다운 받아 ../WEB-INF/lib 에 추가.

2. <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> 를 JSP 파일에 추가.

 

ex)

 

1. c:out - 변수의 값 출력

1
<c:out value="출력할 값" />
cs

2. c:set - 변수에 값을 저장. (setAttribute)

1
<c:set var="변수명" value="저장 할 값" />
cs

3. c:if - if문 조건이 true 이면 출력

1
2
3
<c:if test="조건">
..
</c:if>
cs

4. c:remove - 변수 제거

1
<c:remove var="변수이름" />
cs

5. c:choose - if, else 문

1
2
3
4
5
6
7
8
9
10
11
<c:choose>
    <c:when test="조건1">
    ...
    </c:when>
    <c:when test="조건2">
    ...
    </c:when>
    <c:otherwise>
    ...
    </c:otherwise>
</c:choose>
cs

6. c:forEach - forEach 문

1
2
3
<c:forEach var="변수" items="${배열 }" begin="시작" end="끝">
    ${변수}
</c:forEach>
cs

7. c;redirect - redirect

1
2
3
<c:redirect url="redirect URL">
    <c:param name="파라미터 이름" value="파라미터 값"/>
</c:redirect>
cs