비전공개미 개발노트
[JSP] session값 지정하고 지정된 값 불러오기 본문
반응형
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
'프로그래밍 > JSP' 카테고리의 다른 글
[JSP] 쿠키를 이용해 로그인했던 아이디 기억하기 (0) | 2022.10.31 |
---|---|
[JSP] 쿠키를 설정하고 확인하기 (0) | 2022.10.12 |
[JSP] jsp:useBean, jsp:setProperty, jsp:getProperty 사용하기 (0) | 2022.10.12 |
[JSP] jsp:include에 jsp:param값을 넘기기 (0) | 2022.10.12 |
[JSP] get.Parameter값을 받아와서 페이지 바꾸기 (0) | 2022.10.12 |
Comments