쿠키설정
쿠키설정
문제
메인화면
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<% request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%
Cookie cookie=new Cookie("Name","EunSeoungJeon");
response.addCookie(cookie);
Cookie cookie1=new Cookie("Email","jjjes758@skuniv.ac.kr");
response.addCookie(cookie1);
%>
<title>Cookie Test-Set Cookie</title>
</head>
<body>
<div align="center">
<h2>쿠키 테스트</h2>
<br>
쿠키 설정이 완료되었습니다.
<br><br>
<a href="Assign03_전은성_cookie_result(2017305072).jsp">쿠키 보기</a>
<a href="Assign03_전은성_cookie_delete(2017305072).jsp">쿠키 삭제</a>
</div>
</body>
</html>
쿠키확인
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cookie Test-Get Cookie</title>
</head>
<body>
<%
String name="";
String mail="";
String cook=request.getHeader("Cookie");
if(cook!=null){
Cookie[] cookies=request.getCookies();
for(int i=0;i<cookies.length;i++){
if(cookies[i].getName().equals("Name")){
name=cookies[i].getValue();
}else if(cookies[i].getName().equals("Email")){
mail=cookies[i].getValue();
}
}
}
%>
name 은 <%=name %> 입니다.<br>
email 은 <%=mail %> 입니다.<br>
</body>
</html>
쿠키삭제
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<%@ page import="javax.servlet.http.Cookie" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cookie Test-Delete Cookie</title>
</head>
<body>
<%
Cookie[] cookies=request.getCookies();
if(cookies!=null){
for(int i=0;i<cookies.length;i++){
cookies[i].setMaxAge(0);
response.addCookie(cookies[i]);
}
}
%>
쿠키가 삭제되었습니다. <a href="Assign03_전은성_cookie_result(2017305072).jsp">쿠키 삭제 확인</a>
</body>
</html>