-
[JSP] JSTL 사용법 정리Web/JSP 2019. 7. 15. 18:21
JSTL ( JSP Standard Tag Library )
사용법 정리
lib폴더에 jstl.jar파일 위치
<c:if> 사용법
// input.jsp <h3>나이입력</h3> <hr> <form action="jstl_test.jsp"> 나이:<input type="text" name="age"><br> <button>입력</button> </form> /////////////////////////////////////////////////////////////////////////////////////// // jstl_test.jsp <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!-- 추가 --> <c:if test="true" > <font><strong>나는 Siri다.</strong></font><br> </c:if> <c:if test="${param.age <20}" > <font color="blue">나이가 20미만입니다.</font> </c:if> <c:if test="${param.age>20}" > <font color="blue">나이가 20이상입니다.</font> </c:if>
<c:choose> 사용법 ( 자바 else~if문과 비슷)
<%-- 나이 20대,30대 체크 --%> <c:choose> <%-- if~else if~else문과 유사 --%> <c:when test="${param.age<20 || param.age>39}"> <font color="green">나이가 20대 또는 30대가 아닙니다!!</font> <br> </c:when> <c:when test="${param.age < 30 }"> <%-- 20~39 --%> <font color="green">나이가 20대 입니다!!</font> <br> </c:when> <c:otherwise> <font color="green">나이가 30대 입니다!!</font> <br> </c:otherwise> </c:choose>
<c:forEach> 사용법 (자바의 for문)
<h4>forEach 테스트</h4> <c:forEach begin="1" end="5" var="i" varStatus="stat" step="2"> 인덱스: ${stat.index}, 카운트: ${stat.count} JSTL안녕!>>>>>>>>${i }<br> </c:forEach> <c:forEach items="${personList }" var="p"> 이름:${p.name }, 나이: ${p.age }, 직업: ${p.job }<br> </c:forEach>
<c:forEach>와 <c:if>문의 함께 쓰기
<%-- JSL 안녕! --%> <c:forEach begin="1" end="5" var="i" varStatus="stat" step="1"> 인덱스: ${stat.index}, 카운트: ${stat.count} <c:if test="${stat.count%2==0 }"> <font color="red">JSTL안녕!>>>>>>>>${i }</font><br> </c:if> <c:if test="${stat.count%2!=0 }"> <font color="blue">JSTL안녕!>>>>>>>>${i }</font><br> </c:if> </c:forEach>
반응형'Web > JSP' 카테고리의 다른 글
[EL] application.getInitParameter를 EL로 변경하기 (0) 2019.07.18 [JSP] DBCP란? (0) 2019.07.16 [JSP] EL사용법 ( Expression Language ) (0) 2019.07.15 [JSP] JSP의 액션종류(c, useBean, setProperty) (0) 2019.07.15 [JSP] El, JSTL 탄생배경 및 사용법 (0) 2019.07.13