01makeCookie.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%request.setCharacterEncoding("UTF-8"); %>
<%@include file="/WEB-INF/inc/header.jsp" %>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="/WEB-INF/inc/top.jsp" %>
<%
Cookie cookie = new Cookie("kim", "donggil");
response.addCookie(cookie);
%>
</body>
</html>
01viewCookie.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%request.setCharacterEncoding("UTF-8"); %>
<%@include file="/WEB-INF/inc/header.jsp" %>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="/WEB-INF/inc/top.jsp" %>
<%
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("kim")){
out.print("์ฟ ํค ์ด๋ฆ : " + cookie.getName() + "<br>");
out.print("์ฟ ํค ๊ฐ : " + cookie.getValue() + "<br>");
}
}
}
%>
</body>
</html>
01modifyCookie.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%request.setCharacterEncoding("UTF-8"); %>
<%@include file="/WEB-INF/inc/header.jsp" %>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="/WEB-INF/inc/top.jsp" %>
<!--
์ฟ ํค์ ๊ธฐ๋ณธ ์ ํจ์๊ฐ : -1 //๋ธ๋ผ์ฐ์ ๊ป๋ค ํค๋ฉด ์ฌ๋ผ์ง
์ฟ ํค์ ๊ธฐ๋ณธ ๊ฒฝ๋ก : ํ์ฌํด๋
-->
<% //kim ์ฟ ํค
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("kim")){
cookie.setValue("changhoon");
response.addCookie(cookie);
//์ฟ ํค๋ ๋ณ๊ฒฝ์ฌํญ์ด ์์๋๋ง๋ค response์ ๋ด์์ ์๋ตํด์ค์ผํ๋ค.
//๊ฐ์ ์ด๋ฆ์ ์ฟ ํค๋ฅผ ์๋ก ์์ฑํด์ ์ ๋ฌํ๋ผ
//Cookie cook = new Cookie("kim", "changhoon");
//response.addCookie(cook);
}
}
}
%>
</body>
</html>
01delete.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%request.setCharacterEncoding("UTF-8"); %>
<%@include file="/WEB-INF/inc/header.jsp" %>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="/WEB-INF/inc/top.jsp" %>
<!-- ์ญ์ ํ๋ ๋ฉ์๋ ๋ฐ๋ก ์์. setMaxAge(0)์ผ๋ก -->
<%
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("kim")){
cookie.setMaxAge(0);
response.addCookie(cookie);
// ์๋ก ์์ฑํด์ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ๋ ์์
}
}
}
%>
</body>
</html>
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Day05(cookie03) (0) | 2021.10.08 |
---|---|
Day05(cookie02) (0) | 2021.10.08 |
Day05(javaBean) (0) | 2021.10.08 |
Day04(<%@ include %>) (0) | 2021.10.07 |
Day04(jsp:forward) (0) | 2021.10.07 |