본문 바로가기

JSP, Servlet/JSP, Servlet 기초

[JSP/Servlet] c태그 사용하기 (<c:forEach begin="" end="" step="">) 활용 - 1

앞에서 배운 c태그를 이용하여 연습을 해보자

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSTL forEach 연습</title>
</head>
<body>
	<c:forEach var="cnt" begin="1" end="10" varStatus="status">
${cnt }<c:if test="${not status.last }">, </c:if>
	</c:forEach>
	<br>
	<br>
	<table border="1" style="width:50%; text-align: center;">
		<tr>
			<td>index</td>
			<td>count</td>
			<td>cnt</td>
		</tr>
		<c:forEach var="cnt" begin="7" end="10" varStatus="status">
			<tr>
				<td>${status.index }</td>
				<td>${status.count }</td>
				<td>${cnt }</td>
			</tr>
		</c:forEach>
	</table><br><br>
	
	<table border="1" style="width:50%; text-align: center;">
		<tr>
			<td>index</td>
			<td>count</td>
			<td>cnt</td>
		</tr>
		<c:forEach var="cnt" begin="1" end="10" varStatus="status" step="2">
			<tr>
				<td>${status.index }</td>
				<td>${status.count }</td>
				<td>${cnt }</td>
			</tr>
		</c:forEach>
	</table>

</body>
</html>

 

 

728x90
반응형