자바 중급 (JAVA-Web) 강좌 자료] 쿠키

 

자바 중급 (JAVA-Web) 강좌 자료] 쿠키

 

 

 

 

실무개발자를위한 실무교육 전문교육센터학원
www.oraclejava.co.kr에 오시면 보다 다양한 강좌를 보실 수 있습니다.

 

 

쿠키


 

서블릿 또는 JSP에서 생성
저장위치는 클라이언트 메모리 또는 HD
문자열만 저장 가능
저장형태는 이름과 값으로 저장
웹서버로 재접속할때 요청 HTTP 헤더에 포함
쿠키 생성 방법

    String strName = name;

  String strValue = URLEncoder.encode(홍길동, "euc-kr");

  Cookie cookie = new Cookie(strName, stryValue);

  cookie.setMaxAge(intSecond);

  cookie.setPath(strURI);

  cookie.setDomain(strDomain);

 
쿠키값 얻기

Cookie[] cookies = request.getCookies();

Cookie cookie = null;

if(cookies != null) {

  for(int i=0; i<cookies.length; i++) {

  String cookieName = cookies[i].getName();

  if(cookieName.equals(name")) {

  cookie = cookies[i];

  }

  }

}

if(cookie!=null) {

  String strValue = URLDecoder.decode(cookie.getValue(), "euc-kr");

}

 

+ Recent posts