JSTL表达式之<c:set>

<c:set>

  <c:set>标签用于保存数据。   语法1:将value的值储存至范围为scope的varName变量之中:   <c:set value="value" var="varName" [scope="{ page|request|session|application }"]/>   语法2:将本体内容的数据储存至范围为scope的varName变量之中:   <c:set var="varName" [scope="{ page|request|session|application }"]>   … 本体内容   </c:set>   语法3:将value的值储存至target对象的属性中:   c:set value="value" target="target" property="propertyName" />   语法4:将本体内容的数据储存至target对象的属性中:   <c:set target="target" property="propertyName">   … 本体内容   </c:set>   它有如下属性属性描述是否必须缺省值:   
名 称 说 明 EL 类型 必须 默认值
value 要被储存的值 Y Object
var 欲存入的变量名称 N String
scope var变量的JSP范围 N String pagescope
target 为一JavaBean或java.util.Map对象 Y Object
property 指定target对象的属性 Y String
    如果指定了target属性, 那么property属性也必须指定。   例:   <c:set value="${test.testinfo}" var="test2" scope="session" />   将test.testinfo的值保存到session的test2中,其中test是一个javabean的实例,testinfo是test对象的属性。   <c:set target="${cust.address}" property="city" value="${city}"/>   将对象cust.address的city属性值保存到变量city中。   教材例程15-3,c_set.jsp,<c:set>标签的应用。
 
  <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>   
  <%@ page contentType="text/html; charset=gb2312" language="java" %>  
  <jsp:useBean id="user" class="com.jspdev.ch3.TestBean"/>
  <html>  
   <head>  
     <title>JSTL:的使用c:set</title>
    </head>  
   <body bgcolor="#FFFFFF">   <hr>  
   设置userName的属性为hellking,然后输出这个属性值:  
   <c:set value="hellking" var="userName"/>   
   <c:out value="${userName}"/>   <hr>
    设置password的属性,属性值在body中,然后输出这个属性值:
   <c:set var="password">   xcsdkjf234dfsgs234234234  
   </c:set>   <c:out value="${password}"/>   <hr>
    设置javaBean的属性,然后输出这些属性值:  
   <c:set value="hk2" target="${user}" property="userName"/>  
   <c:set target="${user}" property="password">   sdf234sdfd   </c:set>   
    userName=<c:out value="${user.userName}"/>,   password=<c:out value="${user.password}"/>.   <hr>
    设置不同的属性,并且指定它们的范围:   
   <c:set value="10000" var="maxUser" scope="application"/>
   <c:set value="20" var="maxIdelTime" scope="session"/>  
   <c:set value="next.jsp" var="nextPage" scope="page"/>  
  </body>  
 </html>
原文地址:https://www.cnblogs.com/sailormoon/p/2828079.html