728x90
4-1. Cookie
main.html
<!DOCTYPE html>
<html lang="ko">
<head>
<title>Bootstrap</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
<p>
<a href="cookieOut.jsp"><button type="button">쿠키 보기</button></a>
<a href="cookieGen.jsp"><button type="button">쿠키 생성</button></a>
<a href="cookieMod.jsp"><button type="button">쿠키 수정</button></a>
<a href="cookieDel.jsp"><button type="button">쿠키 삭제</button></a>
</p>
</body>
</html>
cookieOut.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<p><a href="main.html"><button type="button">메인으로</button></a></p>
<%
Cookie[] cookies = request.getCookies();
for(Cookie cookie:cookies){
if(cookie.getName().equals("name") || cookie.getName().equals("age")){
%>
<%=cookie.getName()%>: <%= cookie.getValue()%><br>
<%
}
}
%>
cookieGen.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<p><a href="main.html"><button type="button">메인으로</button></a></p>
<%
Cookie cookie1 = new Cookie("name", "john");
Cookie cookie2 = new Cookie("age", "12");
response.addCookie(cookie1);
response.addCookie(cookie2);
%>
cookieMod.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<p><a href="main.html"><button type="button">메인으로</button></a></p>
<%
Cookie cookie = new Cookie("age","34");
response.addCookie(cookie);
%>
cookieDel.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<p><a href="main.html"><button type="button">메인으로</button></a></p>
<%
Cookie cookie = new Cookie("age", "34");
cookie.setMaxAge(0);
response.addCookie(cookie);
%>
728x90
'WEB > JSP' 카테고리의 다른 글
[JSP] ch04-02. 장바구니 (0) | 2017.11.15 |
---|---|
[JSP] ch03-07. Include3 (0) | 2017.11.14 |
[JSP] ch03-06. Scope (0) | 2017.11.14 |
[JSP] ch03-05. Forward Login (0) | 2017.11.13 |
[JSP] ch03-04. Redirect Login (0) | 2017.11.13 |
댓글