본문 바로가기

카테고리 없음

[Session] 세션 정보 삭제 ( session invalidate)

[makeForm.jsp]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="set.jsp" method="post">
		아이디 : <input type="text" name="id"><br>
		패스워드 : <input type="password" name="password"><br>
		<input type="submit" value="세션설정">
	</form>
</body>
</html>

 

 

[set.jsp]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	//post방식
	request.setCharacterEncoding("utf-8");

	String id = request.getParameter("id");
	String password = request.getParameter("password");
	
	// 세션등록
	session.setAttribute("id", id);
	session.setAttribute("password", password);
%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h2>세션설정 완료</h2>
	<a href="get.jsp">설정된 세션정보 보기</a>
</body>
</html>

 

 

[get.jsp]

<%@page import="kr.co.mlec.member.MemberVO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<%
	//session에 저장되어있는  member를 MemberVO로 형변환시킴
	MemberVO member = (MemberVO)session.getAttribute("member");
%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<hr>
	<c:choose>
		<!-- 세션에 그 정보가 있니? not empty -->
		<c:when test="${ not empty member }">
			설정된 세션 id : ${ sessionScope.member.id }<br>
			설정된 세션 password : ${ member.password }<br>
		</c:when>
		<c:otherwise>
			설정된 세션 정보 없음<br>
		</c:otherwise>
	</c:choose>
	<a href="remove.jsp">세션삭제</a>
</body>
</html>

 

 

[remove.jsp]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	session.invalidate();
%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h2>세션 삭제 완료</h2>
	<a href="get.jsp">삭제된 세션정보 보기</a>
</body>
</html>