BACK END/JSP

jsp 헷갈리는 태그 정리

dinoelll 2023. 2. 22. 22:54

[세션]

 

세션에 값 넣기

session.setAttribute("name", "kimjihoon")

변수에 넣기

String name = (String)session.getAttribute("name");

 

 

세션 값 빼기(생략함)

request.getSession()

 

String name = (String)session.getAttribute("name");
//유지시간(inactive)
int age = session.getMaxInactiveInterval();
String id = session.getId();
//고유한 세션 id를 정해줌

 

[쿠키]

쿠키 값 빼기

Cookie[] list = request.getCookies(); */

 

쿠키 객체화?

//1. 쿠키 객체화(, 나 - 등  특수 문자는 사용하지 않는다.)
Cookie cookie = new Cookie("name","gyeong_young_na");//key, value . 생성자 초기화임
//2. 쿠키 수명 지정
cookie.setMaxAge(60*10);// 초(10분)
//3. 쿠키 저장(고객 pc) // 고객이 저장 시킨걸까, 내가 저장한걸까//
response.addCookie(cookie);