본문 바로가기

WEB_Programming/Struts

bean:cookie Tag 사용법

bean:cookie Tag - 리퀘스트 쿠키에 대한 스크립팅 변수 정의에 유용한 태그이다.

 

이 태그는 특정 요청에 대한 쿠키 값을 획득할때 유용한 태그이다. (단일 값, 복합 값등의 설정은 multiple속성에 따라 결정된다.) 그리고 define 속성으로 Cookie혹은 Cookie[]형식으로 페이지 영역에서 정의된다. 만약 지정된 이름에 해당하는 쿠키가 지정되어 있지 않은경우 request time예외가 던져진다.


Name Description
id

이 속성은 스크립팅 변수의 이름에 해당한다. 이 값은 scope 속성과 연관되어 있다. 또한 요청된 쿠키에 대한 값을 참조하는 변수가 된다.

multiple

이 속성은 이름에 해당하는 모든 매칭되는 쿠키값을 Cookie[]에 담을 것인지에 대한 내용이다. 만약 이 속성이 설정되어 있지 않은경우 첫번째 값이 Cookie에 저장된다.

name

이 속성은 요청된 쿠키의 이름에 대한 속성이다. 이 값은 획득된 변수 혹은 변수값들에 대한 이름이된다.

value

기본 쿠키값을 반환한다.


Example code :
Creating an Action Class                                               : Not Required here.
Creating Form Bean                                                      : Not Required here.
Defining the global-forwards                                        : Not Required here.
Developing the Action Mapping in the struts-config.xml  : Not Required here.

Developing the beanCookieTag.jsp page
:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<!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=UTF-8">
    </head>
    <h3><font color="#33FF33">Bean Cookie Tag Demo</font></h3>
  <body bgcolor="#999933">
        <bean:cookie id="sess" name="JSESSIONID"/>
        <table border="2">
            <tr>
                <th><font color="#33FF33">Property Name</font></th>
                <th>
                    <font color="#33FF33">Values</font>
                </th>
            </tr>
           
            <tr>
                <td>comment</td>
                <td>
                    <bean:write name="sess" property="comment" />
                </td>
            </tr>
           
            <tr>
                <td>comment</td>
                <td>
                    <bean:write name="sess" property="comment" />
                </td>
            </tr>
           
            <tr>
                <td>comment</td>
                <td>
                    <bean:write name="sess" property="comment" />
                </td>
            </tr>
            <tr>
                <td>domain</td>
                <td>
                    <bean:write name="sess" property="domain" />
                </td>
            </tr>
            <tr>
                <td>maxAge</td>
                <td>
                    <bean:write name="sess" property="maxAge" />
                </td>
            </tr>
            <tr>
                <td>path</td>
                <td>
                    <bean:write name="sess" property="path" />
                </td>
            </tr>
            <tr>
                <td>name</td>
                <td>
                    <bean:write name="sess" property="name" />
                </td>
            </tr>  
            <tr>
                <td>value</td>
                <td>
                    <bean:write name="sess" property="value" />
                </td>
            </tr>
            <tr>
                <td>secure</td>
                <td>
                    <bean:write name="sess" property="secure" />
                </td>
            </tr>
           
        </table>    
    </body>
</html>

Add the following line in the index.jsp to call the form.
<a href="beanCookieTag.jsp">beanCookieTagDemo</a><br/>?/font>

Building and Testing the Example  :
Build , deploy and Test  the application .
Open the browser and navigate to the beanCookieTag.jsp page
Your browser displays the following page beanCookieTag.jsp and see the output.

Output:


Above actions   displays the working of beanCookieTag..

'WEB_Programming > Struts' 카테고리의 다른 글

3. Building View Components  (0) 2008.06.13
2. Building Model Components  (0) 2008.06.12
bean:define Tag 사용법  (0) 2008.06.10
Struts1 애플리케이션 작성 단계  (0) 2008.06.10
Img Tag<html:img>: 사용법  (0) 2008.06.10