Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter07 : 01_session 본문

JSP

chapter07 : 01_session

GAWON 2023. 5. 23. 18:34
<%@ 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>
<script type="text/javascript">
	function saveSession(){
		location.href='Ex07_04_session_save.jsp';
	}
	function removeSession(val){
		location.href='Ex07_03_session_remove.jsp?type='+ val;
	}
	function initSession(){
		location.href='Ex07_02_session_init.jsp';
	}
</script>
</head>
<body>
	<h1>세션 관리하기</h1>
	<div>세션에 정보 저장하기<input type="button" value="확인" onclick="saveSession();"></div>
	<div>세션 정보 삭제하기<input type="button" value="확인" onclick="removeSession('name');"></div>
	<div>세션에 정보 초기화하기<input type="button" value="확인" onclick="initSession();"></div>
	
	<br/><hr/>
	
	<%
		//세션에 저장된 데이터 (이름, 나이)확인
		String name = null;
		String age = null;
		
		if(session.getAttribute("name") == null){
			name = "이름없음";
		}else{
			name=(String)session.getAttribute("name");
			//getAttribute() 의 리턴 타입은 Object이므로 캐스팅 필요
		}
		
		if(session.getAttribute("age") == null){
			age = "나이없음";
		}else{
			age = (String)session.getAttribute("age");
			
		}
	%>
	<h1>세션 확인하기</h1>
	<h3>세션에 저장된 이름 = <%=name %></h3>
	<h3>세션에 저장된 나이 = <%=age %></h3>
	
</body>
</html>

'JSP' 카테고리의 다른 글

chapter07 : 03_session_remove  (0) 2023.05.23
chapter07 : 02_session_init  (0) 2023.05.23
chapter06 : 03_page_move  (0) 2023.05.23
chapter06 : 02_page_move  (0) 2023.05.23
chapter06 : 01_page_move  (0) 2023.05.23