카테고리 없음

[JSP][JSTL] For -> Foreach

너래쟁이 2018. 5. 7. 05:24


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!-- JSTL 라이브러리에서 제공하는  태그를 사용하기 위해 기술한다  -->
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>JSTML : Core Library</title>
</head>
<body>
    <form name=form1 method="post" action="Sel.jsp">
        <jsp:useBean id="eltest" class="el.test.Eltest" scope="session"/>
        <select name="sel">
        <%
            for(String item:eltest.getProductlist())
            {
                out.println("<option>"+item+"</option>");
            }
        %>
        
        <!-- foreach문으로 바꾸기  -->
        </select>
        <br>
        <input type="submit" value="선택"/>
    </form>
</body>
</html>
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!-- JSTL 라이브러리에서 제공하는  태그를 사용하기 위해 기술한다  -->
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>JSTML : Core Library</title>
</head>
<body>
    <form name=form1 method="post" action="Sel.jsp">
        <jsp:useBean id="eltest" class="el.test.Eltest" scope="session"/>
        <select name="sel">
            <c:forEach var="item" items="${eltest.getProductlist()}">
                <option>${item}</option>
            </c:forEach>
        </select>
        <br>
        <input type="submit" value="선택"/>
    </form>
</body>
</html>
cs