🎈 ArrayList 값을 담기
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
ArrayList<String> datas = new ArrayList<>();
datas.add("Hello");
datas.add("JSP");
datas.add("너무");
datas.add("즐거워요");
session.setAttribute("msg", datas);
response.sendRedirect("attribute4.jsp");
%>
</body>
</html>
- ArrayList datas 를 session객체에 담아서
- redirect 로 전송
🎈 ArrayList 값을 꺼내기
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<% ArrayList<String> datas = (ArrayList)session.getAttribute("msg");
for(int i = 0; i < datas.size(); i++){
String result = datas.get(i);
out.println(result + "</br>");
}
%>
</body>
</html>
- session은 Object 타입으로 저장하기 때문에 형변환 필요