Programming/jsp2014. 3. 31. 20:48
쿠키는 로그인 정보나 장바구니 등에 사용되는
데이터를 클라이언트에 저장하는 기술이다.

[링크 : http://en.wikipedia.org/wiki/HTTP_cookie]

기본적으로 쿠키는 보안에 취약한 단점이 있어 주의해서 사용해야 하며
이를 보완하기 위해 도메인과 경로를 이용하여 접근을 막는 방법이 존재한다.
하지만 클라이언트 쿠키 저장소에 직접 접근을 막을수는 없으니 이래저래 보안이 취약하긴 매한가지.
void setDomain(String domain)
Specifies the domain within which this cookie should be presented.

void setPath(String uri)
Specifies a path for the cookie to which the client should return the cookie. 

jsp에서는 Cookie 클래스를 통해 쿠키를 생성하며
클라이언트에 저장된 쿠키를 서버에서 접근이 가능해지는 구조이다.

쿠키는 한글입력 불가하나 일일이 인코딩해서 사용하면 가능하다.
URLEncoder.encode("한글","euc-kr")
URLDecoder.decode(cookie.getValue(), "euc-kr") 
 
 
쿠키는 보안을 위해 유효시간을 지니며
setMaxAge를 통해 파기 할때 까지의 시간을 초 단위로 지정할 수 있다.
0으로 설정시에는 0초후 파기되므로, 쿠키를 파기하는데 주로 사용된다.
setMaxAge
public void setMaxAge(int expiry)
Sets the maximum age in seconds for this Cookie.
A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.

A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.

Parameters:
expiry - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie


+ 2014.04.02 추가
setPath() 메소드는 절대경로로 먹는 느낌
webContent가 존재하는 최상위 경로로 부터 전체 경로를 적어야 한다.
그게.. "쿠키의 경로는 쿠키를 설정하는 서브릿을 포함해야 한다"의 의미이려나?
게다가 이클립스의 경우 프로젝트 명으로 폴더를 하나더 들어가기에
/프로젝트명/폴더 식으로 점점 더 길어진다. -_-a
request.getContextPath() 를 추가해주는게 좋을지도..

setPath

public void setPath(java.lang.String uri)
Specifies a path for the cookie to which the client should return the cookie.

The cookie is visible to all the pages in the directory you specify, and all the pages in that directory's subdirectories. A cookie's path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.

Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.

Parameters:
uri - a String specifying a path
See Also:
getPath() 

'Programming > jsp' 카테고리의 다른 글

jdbc URL 구조  (0) 2014.04.01
jsp action tag / <jsp:useBean  (0) 2014.03.31
jsp 액션 태그 - <jsp:  (0) 2014.03.28
jsp error 페이지 사이즈 제한(IE)  (0) 2014.03.27
jsp buffer  (0) 2014.03.27
Posted by 구차니