JSTL Scope Demo : Variable Scope « JSTL « Java Tutorial






<%@ 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>
<%@ 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>
<%@ 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>
  Download:  JSTLScopeDemo.zip( 5,182 k)








24.11.Variable Scope
24.11.1.JSTL Scope Demo