wrkbrs

JSTL [Core 라이브러리] : forEach -배열출력- [items] 본문

JSP

JSTL [Core 라이브러리] : forEach -배열출력- [items]

zcarc 2018. 10. 30. 14:14



LunchMenu.jsp :



<%@page import="java.util.ArrayList"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<%

        /* ====String 배열===== */

        String[] arr = {"순두부","된장찌개","제육덮밥"};

        request.setAttribute("menu", arr);

       

        /* ====ArrayList 배열===== */

        ArrayList<String> arr1 = new ArrayList<String>();

        arr1.add("순두부1");

        arr1.add("된장찌개1");

        arr1.add("제육덮밥1");

        request.setAttribute("menu1", arr1);

%>

 

<jsp:forward page="LunchMenuView.jsp" />

 


LunchMenuView.jsp



<%@ 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>JSTL 코어 라이브러리 : forEach / items 배열출력실습</title>

</head>

<body>

        <h3>String 배열</h3>

        <ul>

        <c:forEach var="dish" items="${menu}">

               <li> ${dish }</li>

        </c:forEach>

        </ul>

 

<hr>

 

        <h3>ArrayList 배열</h3>

        <ul>

        <c:forEach var="dish" items="${menu1}">

               <li> ${dish }</li>

        </c:forEach>

        </ul>

 

</body>

</html>

 

 

 

 

 

 

 

 

 

 



출처: http://whdvy777.tistory.com/entry/JSTL-Core-라이브러리-forEach-배열출력-items [DB전문가를 꿈꾸며!!]