・쿠키는 클라이언트(브라우저)에 객체로 저장되지만 세션은 서버에 객체로 저장되기 때문에 보안에 강하다.

쿠키는 4kb 짜리 300개가 최대 용량이지만, 세션은 로컬에 저장되는 것이 아니라 서버에 저장되기 때문에 데이터한계가없다.

브라우저 1개당 하나의 세션객체를 생성할 수 있다.


・session은 new를 사용하지 않아도 기본적으로 생성되어 있는 내부 객체이다. 따라서, session.setAttribute(세션이름,세션데이터)처럼 메서드나 프로퍼티를 바로 사용가능하다


・session.getAttribute(세션이름)의 리턴값은 Object 타입으로 정해져있다.


・c:/apache-tomcat-8.5.23/conf/web.xml에 세션정보가이 저장된다.즉, 서버에 세션정보가 저장된다.

























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
 
 
<%
    session.setAttribute("id""thisIsId");
    session.setAttribute("pw""12345678");
    session.setAttribute("bank""국민은행");
    session.setAttribute("account""123123");
%>
 
    <a href="./sessionTest3.jsp">click</a>
</body>
</html>
cs






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
<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
    <%
    String id;
    Object obj1 = session.getAttribute("id");
    id = obj1.toString();
    out.println(id+"</br>");
    
    
    ////////////////////////////////////////////////
    String sKey;
    String sVal;
    
    Enumeration infos = session.getAttributeNames();
    while(infos.hasMoreElements()){
        sKey=infos.nextElement().toString();
        sVal=session.getAttribute(sKey).toString();
        out.println(sKey + ":" + sVal +"</br>");
    }
    
    %>
</body>
</html>
cs


・session.getAttribute의 리턴값은 Object 타입이다.


・session.getAttributeNames의 리턴값은 Enumeration 타입이다.











+ Recent posts