EL

9.forEach-varStatus 속성의 사용

Jungsoomin :) 2020. 7. 15. 18:37

forEach태그에는 var , items , begin , end , step 의 속성이 있다.

 

status객체의 이름을 status로 잡고 getter 프로퍼티로 끌어다쓰는 듯 하다. 즉 상태를 알려주는 객체인듯 하다.

  • ${status.current} 현재 for문의 해당하는 번호

  • ${status.index} 해당 인덱스넘버

  • ${status.count} 출력 카운트

  • ${status.first} 첫 번째인지 여부 >>>> c:if 의 test 속성에 쓰이는 듯함

  • ${status.last} 마지막인지 여부  >>>> c:if 의 test 속성에 쓰이는 듯함

  • ${status.begin} for문의 시작 번호

  • ${status.end} for문의 끝 번호

  • ${status.step} for문의 증가값

<body>
<%--
	forEach의 varStatus 속성
		(javax.servlet.jsp.jstl.core.LoopTagStatus)
--%>
<%
	String[] arr ={"java","script","css","python","matrix","c++"};
request.setAttribute("arr", arr);
%>

<table class="table" border="1" style="border-collapse: collapse;">
	<tr>
		<th>index</th>
		<th>count</th>
		<th>item</th>
	</tr>
	<c:forEach var="item" items="${arr}" varStatus="status" begin="3">
		<tr>
			<td>${status.index }</td>
			<td>${status.count }</td>
			<td>${item }</td>
		</tr>
	</c:forEach>
</table>

</body>