📆 Today I Learned(개발언어학습)/JSP
Day05(cookie02)
JinSeong
2021. 10. 8. 18:38
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>
파일경로