cookie 내장 객체는 익스프레션 언어에서 다음과 같이 사용합니다
${cookie.이름} 또는 ${cookie["이름"]}
하지만 이렇게 쓰면 쿠키의 값이 아닌 쿠키 객체를 가져오므로 값을 가져오려면 다음과 같이 VALUE를 추가해야합니다.
${cookie.이름.value} 또는 ${cookie.이름["value"]}
아니면
${cookie["이름"].value 또는 ${cookie["이름"]["value"]}
다음은 쿠키를 저장하고 불러오는 예제입니다. 불러올 때는 익스프레션 언어를 사용해 봅시다.
CookieDataWriter.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
Cookie cookie = new Cookie("NAME", "Gakari");
response.addCookie(cookie);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
쿠키값 저장 완료
</body>
</html>
CookieDataReader.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
쿠키값 읽기 ${cookie.NAME.value}
</body>
</html>
실행 화면
쿠키 값 저장 후
쿠키 값을 읽어오면 잘 불러옴을 알 수 있습니다.
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet - 익스프레션 언어 javabean의 프로퍼티(Property) 가져오기 (0) | 2016.01.11 |
---|---|
JSP/Servlet - 익스프레션 언어 Hash Map 객체를 출력하기 (0) | 2016.01.11 |
JSP/Servlet - 익스프레션 언어 List 객체 사용 방법 (0) | 2016.01.10 |
JSP/Servlet - 익스프레션 언어 initParam 내장 객체 사용 방법 (0) | 2016.01.10 |
JSP/Servlet - 익스프레션 언어 (애트리뷰트 및 param, paramValues) (0) | 2016.01.06 |
JSP/Servlet - setAttribute, getAttribute, removeAttribute 메소드에 사용법 (0) | 2016.01.05 |
JSP/Servlet - 웹애플리케이션 초기화 파라미터 (0) | 2016.01.05 |
JSP/Servlet - 서버 및 서블릿 환경 정보 가져오기(ServletContext) (0) | 2016.01.05 |