-
세션 (session)JSP 2023. 3. 22. 12:41
세션 이란?
: 쿠키가 클라이언트 측의 데이터 보관소라면 세션은 웹 브라우저와 관련된 정보를 저장하는 장소이다.
세션으로 로그인 만들기
- if 문으로 조건을 확인한 뒤
session.setAttribute("세션속성명" , 값) 을 선언한 것으로 session에서 로그인 처리가 완료된 것이다.
** 이때 저장된 Attribute를 불러올때 getAttribute("세션속성명") 을 선언하면 Object 형태로 리턴값이 온다는 것을 명심하자
로그인 확인
- getAttribute의 타입을 고려해서 String으로 변환하고 memberId 가 있음을 확인하는 것으로 로그인 되었음을 알 수 있다.
로그아웃
로그아웃 처리 session.invalidate(); -> 현재 세션에서 로그아웃 한다. session.removeAttribute("세션명"); -> 동일하게 로그아웃 효과를 낼 수 있지만, 세션 명을 추가해줘야하는 번거로움이 있다.
'JSP' 카테고리의 다른 글
프론트엔드와 백엔드 / JDBC 세팅 (0) 2023.03.23 c: 코어태그 와 fmt: 국제화 태그 (0) 2023.03.23 쿠키 (cookie) (0) 2023.03.22 자바빈 , <jsp:useBean> 액션 태그 (0) 2023.03.22 <jsp:forward> 액션 태그 사용법 (0) 2023.03.21