본문 바로가기

JAVA/JSP & Servlet

익스프레션 언어(expression language) ArrayList

FruitsInput.jsp

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

    pageEncoding="UTF-8"%>

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

 

<%

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

        items.add("딸기");

        items.add("오렌지");

        items.add("복숭아");

        request.setAttribute("fruits", items);

       

        RequestDispatcher dispather = request.getRequestDispatcher("FruitsView.jsp");

        dispather.forward(request, response);

 

%>

 

 

 

FruitsView.jsp

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

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>익스프레션 : List 객체 항목 출력</title>

</head>

<body>

 

<h3>이번달 과일 판매 순위</h3>

1. ${fruits[0] }<br>

2. ${fruits[1] }<br>

3. ${fruits[2] }<br>

 

</body>

</html>