JSP/COOKIE
chapter04 : cookie_remove
GAWON
2023. 5. 24. 09:17
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!--
쿠키 삭제는 기존 쿠키의 유효 시간을 0으로한다
1.이름이 name인 쿠키 삭제
-->
<%
Cookie[] cookiebox = request.getCookies();
if(cookiebox != null && cookiebox.length > 0){
for(int i=0; i<cookiebox.length; i++){
if(cookiebox[i].getName().equals("name")){
Cookie bisket = new Cookie("name","");
bisket.setMaxAge(0);
response.addCookie(bisket);
out.print("쿠키 값을 삭제하였습니다.");
}
}
}else{
out.print("쿠키가 존재하지 않습니다.");
}
%>
</body>
</html>