JSP/JSTL
chapter06 : JSTL1 / JSTL2
GAWON
2023. 5. 24. 18:41
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="Ex06_JSTL2.jsp">
<h3>일반 forEach연습</h3>
<p>최소 크기 : <input type ="number" name="num1" min="1" max="7"></p>
<p>최대 크기 : <input type ="number" name="num2" min="1" max="7"></p>
<hr>
<h3>향상 forEach연습</h3>
<input type ="checkbox" name="foods" value="한식">한식
<input type ="checkbox" name="foods" value="양식">양식
<input type ="checkbox" name="foods" value="중식">중식
<input type ="checkbox" name="foods" value="일식">일식
<input type ="checkbox" name="foods" value="분식">분식
<br>
<input type="submit" value="전송">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 1. 최소 값, 최대 값, 최소 값 ~ 최대 값 화면에 출력 -->
<!-- 최소, 최대 값을 변수에 저장 -->
<c:choose>
<c:when test="${param.num1 gt param.num2 }">
최소 값 : ${param.num2}
최대 값 : ${param.num1}
<c:set var="start" value="${param.num2 }"/>
<c:set var="end" value="${param.num1 }"/>
</c:when>
<c:otherwise>
최소 값 : ${param.num1}
최대 값 : ${param.num2}
<c:set var="start" value="${param.num1 }"/>
<c:set var="end" value="${param.num2 }"/>
</c:otherwise>
</c:choose>
<c:forEach var="i" begin="${start }" end="${end }" step="1">
${i }
</c:forEach>
<!-- 2. 향상 forEach 이용하여 음식 종류들 출력 -->
<c:forEach var="food" items="${paramValues.foods }">
${food }<br>
</c:forEach>
</body>
</html>