Set Value for Variable : Set « JSTL « Java Tutorial






<%@ 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>
<%@ 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" %>
<html>
  <head>
    <title>Catch an Exception</title>
  </head>

  <body>
    <c:catch var="e">
    <c:set var="x" value="10" scope="page" />

    <c:set var="y" value="five" scope="page" />

    x divided by y is 
    <c:out value="${x/y}" />

    <br />
    </c:catch>

    <br />
    <c:if test="${e!=null}">The caught exception is:
    <c:out value="${e}" />

    <br />
    </c:if>

    <c:if test="${e==null}">No exception was thrown
    <br />
    </c:if>
  </body>
</html>
  Download:  JSTLSetValueForVariable.zip( 1,247 k)








24.9.Set
24.9.1.JSTL Set Without Body
24.9.2.JSTL Set With Body
24.9.3.Set Value for Variable
24.9.4.Set Comma Delimited String to Variable
24.9.5.Remove Variable
24.9.6.Set Variable To Page Scope
24.9.7.Set Variable Scope to Request
24.9.8.Set Variable Scope Page
24.9.9.Set Variable as Session Scope
24.9.10.Set Variable Scope to Application
24.9.11.Do Calculation In Set