<c:set> Tag
The <c:set> tag is used to set variable values and object properties.
The <c:set> tag is the twin brother of the <jsp:setProperty> action tag.
This tag is very useful because it evaluates the value of an expression and then uses the result to set the value of a JavaBean object or a java.util.Map object.
Syntax Format
<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 | Value to store | no | Content of the body |
| target | Object whose property is to be modified | no | None |
| property | Property to be modified | no | None |
| var | Variable to store information | no | None |
| scope | Scope of the var attribute | no | Page |
If the target attribute is specified, the property attribute also needs to 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 标签实例</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:out value="${salary}"/>
</body>
</html>
The execution result is as follows:
4000
Other Extensions
JSP Standard Tag Library