관리 메뉴

쿰뱅이

Cookie 와 Session 정보 보기 본문

WEB/JSP

Cookie 와 Session 정보 보기

주년 2011. 10. 11. 13:59
반응형

// ViewCookieSessionInfo.jsp

 

<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.util.*" %>
<html>
<head><title>쿠키 세션사용예제(세션확인)</title></head>
<body>

세션 정보
<%

   Enumeration en = session.getAttributeNames();//이뉴멀래이션 객체를 이용하여서 session의 모든 이름을 받아 옵니다
 while(en.hasMoreElements()){  

  String name = (String)en.nextElement(); //세션의 이름이 남아 있는동안(더이상의 세션이 없으면 종료)
  String value = (String)session.getAttribute(name); //세션의 이름을 받습니다
  out.println("session name : " + name + "<br>"); //name을 프린트
  out.println("seesion value " + value + "<br>"); //value를 프린트
 }
 %>

--------------------------------------------------------<br>

쿠키정보
<%
 Cookie[] cookies = request.getCookies();
 if(cookies!=null){
  for(int i=0; i<cookies.length;++i){
%>
    Cookie Name : <%=cookies[i].getName()%><br>
    Cookie Value : <%=cookies[i].getValue()%><br>
<%
  }
 }  
%>
</body>
</html>


반응형