Cookie&Session

[Session] 세션 생성

퓨어맨 2022. 5. 16. 10:03
<%@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>
	<h1>세션 생성</h1>
	<%
		// 세션에 데이터 저장하기
		// 1. 세션 객체 생성
		// HttpSession session = request.getSession();
		// JSP 내장객체에 session이 포함되어있음

		// 2. 세션에 데이터 저장하기
		// setAttribute("Name", (Object)value);
		// 저장할때 업캐스팅
		session.setAttribute("int", 100);
		
		session.setAttribute("str", "세션에 값 저장하기");
		
		ArrayList<String> list = new ArrayList<String>();
		
		list.add("str1");
		list.add("str2");
		list.add("str3");
		list.add("str4");
		list.add("str5");
		
		session.setAttribute("list", list);
	%>
	
		<a href="ex06selectSession.jsp">세션 조회</a>
</body>
</html>

 

 

 

'Cookie&Session' 카테고리의 다른 글

[Session] 세션 수정  (0) 2022.05.16
[Session] 세션 조회  (0) 2022.05.16
[Cookie] 최근 본 상품 내역 출력  (0) 2022.05.16
[Cookie] 쿠키 수정  (0) 2022.05.16
[Cookie] 쿠키 조회  (0) 2022.05.16