<c:set> Tag
The <c:set> tag is used to set the value of variables and object properties.
The <c:set> tag is akin to the <jsp:setProperty> action tag's twin.
This tag is particularly useful because it evaluates the expression's value and then uses the result to set the value of a JavaBean object or a java.util.Map object.
Syntax
<c:set
var="<string>"
value="<string>"
target="<string>"
property="<string>"
scope="<string>"/>
Attributes
The <c:set> tag has the following attributes:
Attribute | Description | Required | Default Value |
---|---|---|---|
value | The value to be stored | No | Body content |
target | The object whose property is to be modified | No | None |
property | The property to be modified | No | None |
var | The variable to store the information | No | None |
scope | The scope of the var attribute | No | Page |
If the target attribute is specified, the property attribute must also be specified.
Example Demonstration
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:set Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:out value="${salary}"/>
</body>
</html>
The output is as follows:
4000