본문 바로가기

JSP

URL 재작성 메커니즘

쿠키를 사용할 수 없는 웹 환경에서 URL 뒤에 세션 아이디를 붙여서 전송하는 방법


세션 데이터를 저장하는 jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<%

    session.setAttribute("name", "홍길동");

    session.setAttribute("age", new Integer(20));

    session.setAttribute("gender", "");

%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

    세션 데이터가 저장되었습니다 <br /><br />

    <a href=<%=response.encodeURL("ReadSessionData.jsp") %>>세션데이터 읽기</a>

</body>

</html>


 


세션 데이터를 읽는 jsp

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

    이름 : <%=session.getAttribute("name") %><br />

    나이 : <%=session.getAttribute("age") %><br />

    성별 : <%=session.getAttribute("gender") %><br />

</body>

</html>




url 뒤에 세션 아이디가 붙어있는 것을 확인할 수 있다.

 


'JSP' 카테고리의 다른 글

익스프레션 언어 requestScope  (0) 2013.03.21
서블릿의 라이프 사이클  (0) 2013.03.21
익셉션 처리 실습  (1) 2013.03.20
세션  (0) 2013.03.20
쿠키  (0) 2013.03.20