c:set标签

来源:互联网 发布:互联网金融 知乎 编辑:程序博客网 时间:2024/05/25 16:40
<c:set>标签主要用来将变量保存到JSP 的会话中或JavaBean 的属性中。<c:set>的语法格式为:
<c:set value="value" var="varName"
[scope="{ page|request|session|application }"]/>
上述的表达式实现的功能是将 value 的值储存至范围为scope 的 varName 变量之中,还可以将 value 的值储存至 target 对象的属性中,实现方法为:
< c:set value="value" target="target" property="propertyName" />
下面就是一个<c:set>使用的例子,实现代码如下:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
   <title>cset标签</title>
</head>
<body>
   <c:set var="count" scope="request" value="${2 + 1}" />
   <c:out value="${count}"/><br/>
   <c:set var="count" scope="session" >${2 + 2}</c:set>
   <c:out value="${count}"/><br/>
   <c:set var="count" scope="request" value="${ param.count }" />
   <c:out value="${count}"/><br/>
</body>
</html>
原创粉丝点击