Easy Tutorial
❮ Jstl Format Settimezone Tag Jsp Setup ❯

<x:set> Tag

JSP Standard Tag Library

The <x:set> tag sets a variable to the value of an XPath expression.

If the value of the XPath expression is of boolean type, <x:set> will set a java.lang.Boolean object; if it is a string, it will set a java.lang.String object; if it is a number, it will set a java.lang.Number object.

Syntax

&lt;x:set var="<string>" select="<string>" scope="<string>"/>

Attributes

The <x:set> tag has the following attributes:

Attribute Description Required Default Value
var The variable representing the value of the XPath expression Yes Body
select The XPath expression to be evaluated No None
scope The scope of the var attribute No Page

Example

The following example demonstrates how to use the <x:set> tag:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

<html>
<head>
  <title>JSTL x:set Tag</title>
</head>
<body>
<h3>Books Info:</h3>

&lt;c:set var="xmltext">
  <books>
    <book>
      <name>Padam History</name>
      <author>ZARA</author>
      <price>100</price>
    </book>
    <book>
      <name>Great Mistry</name>
      <author>NUHA</author>
      <price>2000</price>
    </book>
  </books>
</c:set>

&lt;x:parse xml="${xmltext}" var="output"/>
&lt;x:set var="fragment" select="$output//book"/>
<b>The price of the second book</b>: 
&lt;c:out value="${fragment}" />
</body>
</html>

The output is as follows:

BOOKS INFO:
The price of the second book:[[book: null], [book: null]]

JSP Standard Tag Library

❮ Jstl Format Settimezone Tag Jsp Setup ❯