본문 바로가기

PROGRAMMING

Session and Cookies


세션

session.setAttribute("세션name", "세션value");

//세션을 설정

String sessionName = (String)session.getAttribute("세션name");

//앞에서 정의한 세션의 이름을 가져오기

session.setMaxInactiveInterval(60*1);

//세션 유지기간을 설정한다 60*1은 60초 * 1을 의미한다

session.removeAttribute("세션name");

//특정 세션을 지울때

session.invalidate();          

//세션 값을 삭제

 

 

쿠키

 

Cookie[] cookies = request.getCookies();

//쿠키값을 가져온다 배열 형식으로 기져온다는 것을 유념

Cookie cookie = new Cookie("쿠키name", "쿠키value");
//쿠키를 설정하는 부분. 쿠키를 생성한다

cookie.setMaxAge(1*24*60*60);

//쿠키의 유지 기간을 설정 예는 하루를 보관한다는 것이다
response.addCookie(cookie);

//생성한 쿠키를 추가하는 부분

 

for ( int i = 0; i < cookies.length; i++ ) {
System.out.println("쿠키 이름 : "+cookies[i].getName());

System.out.println("쿠키 값 : "+cookies[i].getValue());

}

//만든 쿠키를 보여주는 예제    

'PROGRAMMING' 카테고리의 다른 글

Web Server and Web Application Server  (0) 2009.06.21
Spring and Hibernate Folder Design and necessary Files  (0) 2009.06.21