English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The <c:set> tag

JSP Standard Tag Library

The <c:set> tag is used to set variable values and object properties.

The <c:set> tag is a twin brother of the <jsp:setProperty> action tag.

This tag is very useful because it calculates the value of the expression and then uses the calculated result to set the value of a JavaBean object or java.util.Map object.

Syntax format

<c:set
   var="<string>"
   value="<string>"
   target="<string>"
   property="<string>"
   scope="<string>"/>

Attribute

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

Attribute Description Is it necessary Default value
value The value to be stored No The content of the subject
target The object to which the attribute to be modified belongs No None
property The attribute to be modified No None
var Variable to store information No None
scope The scope of var attribute No Page

If the target attribute is specified, then 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 Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2">/>
<c:out value="${salary}"/>
</body>
</html>

The running result is as follows:

4000

JSP Standard Tag Library