<c:set> 標籤
<c:set>標籤用於設置變數值和對象屬性。
<c:set>標籤就是<jsp:setProperty>行為標籤的孿生兄弟。
這個標籤之所以很有用呢,是因為它會計算運算式的值,然後使用計算結果來設置 JavaBean 對象或 java.util.Map 對象的值。
語法格式
<c:set var="<string>" value="<string>" target="<string>" property="<string>" scope="<string>"/>
屬性
<c:set>標籤有如下屬性:
| 屬性 | 描述 | 是否必要 | 默認值 |
|---|---|---|---|
| value | 要存儲的值 | 否 | 主體的內容 |
| target | 要修改的屬性所屬的對象 | 否 | 無 |
| property | 要修改的屬性 | 否 | 無 |
| var | 存儲資訊的變數 | 否 | 無 |
| scope | var屬性的作用域 | 否 | Page |
如果指定了target屬性,那麼property屬性也需要被指定。
實例演示
<%@ 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>
運行結果如下:
4000

JSP 標準標籤庫