Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter01 : cookie_make 본문

JSP/COOKIE

chapter01 : cookie_make

GAWON 2023. 5. 24. 09:16
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	//1.쿠기 만들기(서버로 쿠키 만들기)
	//cookie cookie = new cookie("쿠기 이름"," 쿠키 값");
	Cookie cookie = new Cookie("id", "admin");
	//쿠키 유효시간 설정(1일)
	cookie.setMaxAge(60*60*24);
	//"쿠키 값"에 공백,콤마,괄호 등을 저장하려면 인코딩을 해야 함
	Cookie bisket = new Cookie("name", URLEncoder.encode("김 씨", "utf-8"));
	//bisket의 유효시간 20분으로 설정
	bisket.setMaxAge(60*20);
	
	//만든 쿠키를 쿠키 저장소에 저장
	response.addCookie(cookie);
	response.addCookie(bisket);
%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<h1>
		쿠키1 이름: <%=cookie.getName() %>
		쿠키1 값 : <%=cookie.getValue() %>
		
		쿠키2 이름: <%=bisket.getName() %>
		쿠키2 값 : <%=URLDecoder.decode(bisket.getValue(),"utf-8") %><%--URLDecoder --%>
		
	</h1>



</body>
</html>

'JSP > COOKIE' 카테고리의 다른 글

chapter05 : id_check1 / id_check2  (0) 2023.05.24
chapter04 : cookie_remove  (0) 2023.05.24
chapter03 : cookie_change  (0) 2023.05.24
chapter02 : cookie_view  (0) 2023.05.24
cookie  (0) 2023.05.24