JSP

JSTL <c:forEach> 커스텀액션

헝그리하트 2013. 3. 21. 23:58

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

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

    pageEncoding="UTF-8"%>

 

<%

    //String[] arr = {"볼고기 백반", "오므라이스", "콩국수"};

    //request.setAttribute("menu", arr);

 

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

    arr.add("불고기 백반");

    arr.add("오므라이스");

    arr.add("콩국수");

    request.setAttribute("menu", arr);

%>

 

<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>Insert title here</title>

</head>

<body>

 

<h3>오늘의 점심 메뉴</h3>

<ul>

<c:forEach

var="dish" items="${menu }">

    <li>${dish }</li>

</c:forEach>

</ul>

</body>

</html>