반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

비전공개미 개발노트

[JSP] session값 지정하고 지정된 값 불러오기 본문

프로그래밍/JSP

[JSP] session값 지정하고 지정된 값 불러오기

비전공개미 2022. 10. 12. 20:02
반응형
SMALL
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.Enumeration" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//session userId값과 userPwd값을 설정
session.setAttribute("userId", "rose");
session.setAttribute("userPwd", "1234");

out.print(session.getAttribute("userId"));
out.print(session.getAttribute("userPwd")+"<br>");

//session.removeAttribute("userPwd"); //선택된 session값을 삭제
//session.invalidate(); //session전체무효화
%>
<br><br>
<%
String name, value;
int i = 0;

Enumeration en = session.getAttributeNames();
while(en.hasMoreElements()){
	i++;
	name = en.nextElement().toString(); //toString()
	value = (String)session.getAttribute(name); //(String)
	out.print("설정된 세션의 속성 이름["+i+"] : " +name+"<br>");
	out.print("설정된 세션의 속성 값["+i+"] : " +value+"<br>");
}
%>
</body>
</html>

 

반응형
LIST
Comments