java.util.List 객체의 항목을 가져다가 출력하는 예제입니다.
ListInput.jsp에서 값을 저장하고 ListPrint.jsp에서 값을 출력합니다.
ListInput.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@page import="java.util.*" %>
<%
ArrayList<String> items = new ArrayList<String>();
items.add("A");
items.add("B");
items.add("C");
request.setAttribute("ALPHA", items);//애트리뷰트를 저장함
RequestDispatcher dispatcher = request.getRequestDispatcher("ListPrint.jsp");
dispatcher.forward(request, response);
%>
<!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>Insert title here</title>
</head>
<body>
</body>
</html>
ListPrint.jsp
<%@ 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>Insert title here</title>
</head>
<body>
리스트 출력
${ALPHA[0]} <BR>
${ALPHA[1]} <BR>
${ALPHA[2]} <BR>
</body>
</html>
출력 화면
다음과 같이 값들이 잘 나옵니다.
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet - <jsp:include> 표준액션의 사용 방법 (0) | 2016.01.14 |
---|---|
JSP/Servlet - 자바의 정적 메소드를 EL 함수로 등록 및 사용 (0) | 2016.01.13 |
JSP/Servlet - 익스프레션 언어 javabean의 프로퍼티(Property) 가져오기 (0) | 2016.01.11 |
JSP/Servlet - 익스프레션 언어 Hash Map 객체를 출력하기 (0) | 2016.01.11 |
JSP/Servlet - 익스프레션 언어 initParam 내장 객체 사용 방법 (0) | 2016.01.10 |
JSP/Servlet - 익스프레션 언어 cookie 내장 객체 사용 방법 (0) | 2016.01.10 |
JSP/Servlet - 익스프레션 언어 (애트리뷰트 및 param, paramValues) (0) | 2016.01.06 |
JSP/Servlet - setAttribute, getAttribute, removeAttribute 메소드에 사용법 (0) | 2016.01.05 |