본문 바로가기

JAVA/JSP & Servlet

익스프레션 언어(expression language) -cookie-

cookie_before.jsp

<%@ 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>