본문 바로가기

Programming/Java/JSP

JSTL 예제

자주 사용하지 않지만 유용한 JSTL예제들 정리함.

1. when/choose
 

<c:choose>

<c:when test="${cateId==20}">

<img src="<%=request.getContextPath()%>/images/02_sub_tab2_shop.jpg" border="0"   usemap="#Map3" />

</c:when>

<c:when test="${cateId==30}">

<img src="<%=request.getContextPath()%>/images/02_sub_tab3_cul.jpg" border="0" usemap="#Map3" />

</c:when>

<c:when test="${cateId==40}">

<img src="<%=request.getContextPath()%>/images/02_sub_tab4_entain.jpg" border="0" usemap="#Map3" />

</c:when>

<c:otherwise>

<img src="<%=request.getContextPath()%>/images/02_sub_tab1_food.jpg" border="0"   usemap="#Map3" />

</c:otherwise>

</c:choose>


2. set 연산
<c:set var="i" value="0" />
<c:set var="i" value="${i+1}" />

3. foreach : 지정 회수만큼 반복
<c:forEach var="i" begin="1" end="6" step="1">

<tr>

<td height="25" class="k_label13">쿠폰아이디 ${i}</td>

<td height="25" class="dataLabel12L2" bgcolor="#FFFFFF">

<input type="text" name="arrStrCpnId" maxlength="20" style="width: 50%; height: 20px" />

</td>

</tr>

</c:forEach>