<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>cookie</title>
</head>
<body>
<form action="cookie_ok.jsp" method="post">
아이디 : <input type="text" name="id" /><br />
이메일 : <input type="text" name="email" /><br />
<input type="submit" value="전송" /><br />
<br />
<a href="cookie_delete.jsp">쿠키삭제</a>
</form>
</body>
</html>
cookie_ok.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String email = request.getParameter("email");
Cookie cookie1 = new Cookie("id", id);
Cookie cookie2 = new Cookie("email", email);
cookie1.setMaxAge(3600);
cookie2.setMaxAge(3600);
response.addCookie(cookie1);
response.addCookie(cookie2);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSP</title>
</head>
<body>
쿠키가 저장되었습니다.<br />
<a href="cookie_after.jsp">쿠키확인</a>
</body>
</html>
cookie_after.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSP</title>
</head>
<body>
쿠키내용 값 : ${cookie.id.value }<br />
쿠키내용 값 : ${cookie['id']['value'] }<br />
쿠키내용 값 : ${cookie['id']['domain'] }<br />
쿠키내용 값 : ${cookie['id']['path'] }<br />
쿠키내용 값 : ${cookie['id']['maxAge'] }<br />
쿠키내용 값 : ${cookie.email.value }<br />
</body>
</html>
'JAVA > JSP & Servlet' 카테고리의 다른 글
익스프레션 언어(expression language) empty (0) | 2013.03.21 |
---|---|
익스프레션 언어(expression language) 산술, 비교, 논리, 조건 -param- (0) | 2013.03.21 |
익스프레션 언어(expression language) 기본[requestScope ,pageScope ] (0) | 2013.03.21 |
JSP 변수의 범위 (0) | 2013.03.20 |
서블릿(servlet)의 라이프 사이클 (getInitParameter, getContextPath) (2) | 2013.03.20 |