02cookiePath.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 path1 = new Cookie("path1", "path1");
path1.setPath(request.getContextPath()+"/09cookie/path1");
Cookie path2 = new Cookie("path2", "path2");
path2.setPath("/study/09cookie/path2");
Cookie basic = new Cookie("basic", "basic");
Cookie absolute = new Cookie("absolute", "absolute");
absolute.setPath("/");
response.addCookie(path1);
response.addCookie(path2);
response.addCookie(basic);
response.addCookie(absolute);
//์ฟ ํค๊ฒฝ๋ก๋ ๊ฒฝ๋ก์ง์ ๋ ๊ณณ์ ํ์๊ฒฝ๋ก์์๋ ์ ๋ถ ์ฌ์ฉ๊ฐ๋ฅ
//๊ฒฝ๋ก์ง์ ์ํ๋ฉด ๊ธฐ๋ณธ์ ํ์ฌํด๋
//path1 : absolute, basic, path1
//09cookie : absolute, basic
// / : absolute
%>
</body>
</html>
02cookieAll.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){
out.print("์ฟ ํค ์ด๋ฆ : " + cookie.getName() + "<br>");
out.print("์ฟ ํค ๊ฐ : " + cookie.getValue() + "<br>");
}
}
%>
</body>
</html>
ํ์ผ๊ฒฝ๋ก
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Day05(cookie04) (0) | 2021.10.08 |
---|---|
Day05(cookie03) (0) | 2021.10.08 |
Day05(cookie01) (0) | 2021.10.08 |
Day05(javaBean) (0) | 2021.10.08 |
Day04(<%@ include %>) (0) | 2021.10.07 |