o Hidden Form Variable q Form type form
o 숨겨진 필드(Hidden Form Variable) q Form 데이터를 전송할 때 type을 이용해서 값을 넘김 <form name="frm. Name" method="post" action="***. jsp">. . . <input type="hidden" name="confirm. Id" value="<%=login. Id%>">. . . </form> q 소스보기를 통해서 정보가 노출
q 쿠키 생성(꼬리표 만들기) Cookie my. Cookie=new Cookie(“Cookie. Name”, ”What a. Delicious Cookie it is!”); q 쿠키 셋팅(꼬리표에 정보 기록하기) my. Cookie. set. Value(“Wow!”); q 쿠키 전달(꼬리표 붙이기) response. add. Cookie(my. Cookie);
q 쿠키 읽기(꼬리표 읽기) request. get. Cookies(); q 쿠키 수명주기 Cookies. set. Max. Age(int expiry);
쿠키 사용 예제 //Cookie. jsp 01 <%@ page content. Type="text/html; charset=euc-kr" %> n Cookie 사용 예제 – 쿠키를 생성하는 페이지를 02 <html> 03 <head> 04 <title>Cookie</title> 05 </head> 06 <% 07 String cookie. Name = "my. Cookie"; 08 Cookie cookie = new Cookie(cookie. Name, "Apple"); 09 cookie. set. Max. Age(60); //One minute 10 cookie. set. Value("Melone"); 11 response. add. Cookie(cookie); 12 %> 13 <body> 14 <h 1>Example Cookie</h 1> 15 <P> 16 쿠키를 만듭니다. 17 쿠키 내용은 <a href="Taste. Cookie. jsp">여기로</a>!!! 18 </P> 19 </body> 20 </html> 작성하고 저장
//Taste. Cookie. jsp 01 <%@ page content. Type="text/html; charset=euc-kr" %> 02 <html> 03 <head> 04 <title>Taste Cookie</title> 05 </head> n Cookie 사용 예제 – 쿠키를 생성하는 페이지를 06 <body> 07 <h 1>Example Cookie</h 1> 08 <% 09 Cookie[] cookies = request. get. Cookies(); 10 if(cookies!=null){ 11 for(int i=0; i<cookies. length; ++i){ 12 if(cookies[i]. get. Name(). equals("my. Cookie")){ 13 %> 14 Cookie Name : <%=cookies[i]. get. Name()%> 15 Cookie Value : <%=cookies[i]. get. Value()%> 16 17 <% 18 } 19 } 20 } 21 %> 22 </body> 23 </html> 2. 3 쿠키를 구현할 수 있는 쿠키 클래스 작성하고 저장
q 세션 생성 session. set. Attribute(“my. Session”, ”session value”); q 세션의 유지시간 설정 session. set. Max. Inactive. Interval(60*5); //세션 유지시간을 5분으로 설정 q 세션 속성 삭제 session. remove. Attribute(“my. Session”); q 세션 삭제 session. invalidate();
세션 사용 예제 //Create. Session. jsp n 01 Cookie 사용 예제 – 쿠키를 생성하는 페이지를 작성하고 <%@ page content. Type="text/html; charset=euc-kr" %> 02 <html> 03 <head> 04 <title>세션사용예제(세션생성)</title> 05 </head> 06 <body> 07 <% 08 String str. Id = “hansung"; 09 String str. Pw = "hello"; 10 11 session. set. Attribute("log. ID", str. Id); 12 session. set. Attribute("log. PW", str. Pw); 13 %> 14 세션이 생성되었습니다. 15 16 <a href="View. Session. Info. jsp">세션정보를 확인하는 페이지로 이동</a> 17 </body> 18 </html> 저장
세션 사용 예제 //View. Session. Info. jsp n 01 Cookie 사용content. Type="text/html; 예제 – 쿠키를 생성하는 페이지를 %> 작성하고 <%@ page charset=euc-kr" 02 <%@ page import="java. util. *" %> 03 <html> 04 <head><title>세션사용예제(세션확인)</title></head> 05 <body> 06 <% 07 Enumeration en = session. get. Attribute. Names(); 08 while(en. has. More. Elements()){ 09 String name = (String)en. next. Element(); 10 String value = (String)session. get. Attribute(name); 11 out. println("session name : " + name + " "); 12 out. println("session value " + value + " "); 13 } 14 %> 15 </body> 16 </html> 저장
Create. Session. II. jsp <%@ page content. Type="text/html; charset=euc-kr" %> <html> <head> <title>세션사용예제(세션생성)</title> </head> <body> <% String str. Id = “hansung"; String str. Pw = "hello"; session. set. Attribute("log. ID", str. Id); session. set. Attribute("log. PW", str. Pw); %> 세션이 생성되었습니다. <a href="View. Cookie. Session. Info. jsp">세션정보를 확인하는 페이지로 이동</a> </body> </html>
View. Cookie. Session. Info. jsp <%@ page content. Type="text/html; charset=euc-kr" %> <%@ page import="java. util. *" %> <html> <head><title>세션사용예제(세션확인)</title></head> <body> <% Enumeration en = session. get. Attribute. Names(); while(en. has. More. Elements()){ String name = (String)en. next. Element(); String value = (String)session. get. Attribute(name); out. println("session name : " + name + " "); out. println("seesion value " + value + " "); } %>
------------------------ <% Cookie[] cookies = request. get. Cookies(); if(cookies!=null){ for(int i=0; i<cookies. length; ++i){ %> Cookie Name : <%=cookies[i]. get. Name()%> Cookie Value : <%=cookies[i]. get. Value()%> <% } } %> </body> </html>
o 세션을 사용한 로그인 Session. Member. Login. jsp id pw Session. Member. Login. OK. jsp 회원여부 체크를 위한 Pass. Check() 호출 false true Session. Login. Confirm. jsp 로그인이 허락된 회원일 경우 보여지는 페이지 Session. Log. Out. jsp 로그인 사용자 정보삭제 true false Member. Mgr 1. java Pass. Check() 회원일 경우 true 아닐경우 false
n 세션 사용 로그인 예제 q q Session. Member. Log. In. jsp Session. Member. Log. In. OK. jsp Session. Log. In. Confirm. jsp Session. Log. Out. jsp
<< Session. Member. Log. In. OK. jsp 실행화면 >>
<< Session. Log. In. Confirm. jsp 실행화면 >>
<< Session. Log. In. Confirm. jsp 실행화면 >>
- Slides: 28