본문 바로가기

WEB_Programming/JSTL

10. JSTL의 Scope

1. 스코프 내용 기본
1.1 스코프 설정 jsp
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:set var="scopeVarPage" value="Page Value" scope="page" />

<c:set var="scopeVarRequest" value="Request Value"
scope="request" />

<c:set var="scopeVarSession" value="Session Value"
scope="session" />

<c:set var="scopeVarApplication" value="Application Value"
scope="application" />

<html>
  <head>
    <title>Scope Example</title>
  </head>

  <body>
    <h3>Main File: index.jsp</h3>

    <table border="1">
      <tr>
        <TH>Scoped Variable</th>

        <TH>Current Value</th>
      </tr>

      <tr>
        <td>
        <b>Page Scope</b>

        (scopeVarPage)</td>

        <td>&#160;
        <c:out value="${scopeVarPage}" />
        </td>
      </tr>

      <tr>
        <td>
        <b>Request Scope</b>

        (scopeVarRequest)</td>

        <td>&#160;
        <c:out value="${scopeVarRequest}" />
        </td>
      </tr>

      <tr>
        <td>
        <b>Session Scope</b>

        (scopeVarSession)</td>

        <td>&#160;
        <c:out value="${scopeVarSession}" />
        </td>
      </tr>

      <tr>
        <td>
        <b>Application Scope</b>

        (applicationVarPage)</td>

        <td>&#160;
        <c:out value="${scopeVarApplication}" />
        </td>
      </tr>
    </table>

    <br />

    <br />

    <jsp:include page="included.jsp" />

    <br />

    <br />

    <a href="linked.jsp">[Click Here to View: linked.jsp]</a>
  </body>
</html>

1.2 지정된 스코프 이용 jsp
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
  <head>
    <title>Scope Example</title>
  </head>

  <body>
    <h3>Linked File: linked.jsp</h3>

    <table border="1">
      <tr>
        <TH>Scoped Variable</th>

        <TH>Current Value</th>
      </tr>

      <tr>
        <td>
        <b>Page Scope</b>

        (scopeVarPage)</td>

        <td>&#160;
        <c:out value="${scopeVarPage}" />
        </td>
      </tr>

      <tr>
        <td>
        <b>Request Scope</b>

        (scopeVarRequest)</td>

        <td>&#160;
        <c:out value="${scopeVarRequest}" />
        </td>
      </tr>

      <tr>
        <td>
        <b>Session Scope</b>

        (scopeVarSession)</td>

        <td>&#160;
        <c:out value="${scopeVarSession}" />
        </td>
      </tr>

      <tr>
        <td>
        <b>Application Scope</b>

        (applicationVarPage)</td>

        <td>&#160;
        <c:out value="${scopeVarApplication}" />
        </td>
      </tr>
    </table>
  </body>
</html>

1.3 지정된 스코프 이용 jsp 2
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<table border="1">
  <tr>
    <TH>Scoped Variable</th>

    <TH>Current Value</th>
  </tr>

  <tr>
    <td>
    <b>Page Scope</b>

    (scopeVarPage)</td>

    <td>&#160;
    <c:out value="${scopeVarPage}" />
    </td>
  </tr>

  <tr>
    <td>
    <b>Request Scope</b>

    (scopeVarRequest)</td>

    <td>&#160;
    <c:out value="${scopeVarRequest}" />
    </td>
  </tr>

  <tr>
    <td>
    <b>Session Scope</b>

    (scopeVarSession)</td>

    <td>&#160;
    <c:out value="${scopeVarSession}" />
    </td>
  </tr>

  <tr>
    <td>
    <b>Application Scope</b>

    (applicationVarPage)</td>

    <td>&#160;
    <c:out value="${scopeVarApplication}" />
    </td>
  </tr>
</table>

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

12. JSTL 예외 처리  (0) 2008.06.20
11. JSTL Cookie 처리  (0) 2008.06.20
9. JSTL에서 JavaBeans 사용  (0) 2008.06.20
8. JSTL Set  (0) 2008.06.20
7. JSTL Collection 예제  (0) 2008.06.20