标记<c:out>具有以下属性:
属性 | 描述 | 必需 | 默认值 |
value | 输出的信息 | Yes | None |
default | 反馈输出的信息 | No | body |
escapeXml | True,如果标签转义特殊XML字符 | No | true |
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:out> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:out value="${'<tag> , &'}"/>
</body>
</html>
<c:set>标记具有以下属性:
属性 | 描述 | 必需 | 默认值 |
value | 保存信息 | No | body |
target | 变量的名称,其属性应该修改 | No | None |
property | 要修改的属性 | No | None |
var | 变量的名称存储信息 | No | None |
scope | 变量来存储信息的范围 | No | Page |
如果指定目标,属性也必须指定。
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:set> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:out value="${salary}"/>
</body>
</html>
<c:remove>标签具有以下属性:
属性 | 描述 | 必选 | 默认 |
var | 删除的变量名称 | Yes | None |
scope | 要删除变量的范围 | No | All scopes |
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:remove> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<p>Before Remove Value: <c:out value="${salary}"/></p>
<c:remove var="salary"/>
<p>After Remove Value: <c:out value="${salary}"/></p>
</body>
</html>
<c:catch>标签具有以下属性:
属性 | 描述 | 必选 | 默认 |
var | 变量的名称保存在java.lang。如果抛出的Throwable在body元素内。 | No | None |
实例:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:catch> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:catch var ="catchException">
<% int x = 5/0;%>
</c:catch>
<c:if test = "${catchException != null}">
<p>The exception is : ${catchException} <br />
There is an exception: ${catchException.message}</p>
</c:if>
</body>
</html>
<c:if>标签具有以下属性:
属性 | 描述 | 必需 | 默认 |
test | 条件计算 | Yes | None |
var | 变量名称的存储条件的结果 | No | None |
scope | 变量的范围的存储条件的结果 | No | page |
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
属性:
· <c:choose>标签没有任何属性。
· <c:when>标记有一个属性,下面列出了。
· <c:otherwise>标签没有任何属性。
<c:when>标记具有以下属性:
属性 | 描述 | 必需 | 默认值 |
test | 条件计算 | Yes | None |
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:choose> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<p>Your salary is : <c:out value="${salary}"/></p>
<c:choose>
<c:when test="${salary <= 0}">
Salary is very low to survive.
</c:when>
<c:when test="${salary > 1000}">
Salary is very good.
</c:when>
<c:otherwise>
No comment sir...
</c:otherwise>
</c:choose>
</body>
</html>
c:import>标记具有以下属性:
属性 | 描述 | 必需 | 默认值 |
url | URL检索和导入到页面 | Yes | None |
context | /后面的本地Web应用程序的名称 | No | 目前的应用 |
charEncoding | 为导入数据使用的字符集 | No | ISO-8859-1 |
var | 变量的名称存储导入的文本 | No | Print to page |
scope | 变量作用域用于存储导入的文本 | No | Page |
varReader | 替代变量的名称,暴露的java.io.Reader | No | None |
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:import> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:import var="data" url="http://www.yiibai.com"/>
<c:out value="${data}"/>
</body>
</html>
<c:forEach>标记有以下属性:
属性 | 描述 | 必需 | Default |
items | Information to loop over | No | None |
begin | Element to start with (0 = first item, 1 = second item, ...) | No | 0 |
end | Element to end with (0 = first item, 1 = second item, ...) | No | Last element |
step | Process every step items | No | 1 |
var | Name of the variable to expose the current item | No | None |
varStatus | Name of the variable to expose the loop status | No | None |
<c:forTokens>标签有类似<c:forEach>的属性,除了一个额外的属性delims指定要使用的字符作为分隔符。
属性 | 描述 | Required | Default |
delims | Characters to use as delimiters | Yes | None |
<c:forEach>例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:forEach> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:forEach var="i" begin="1" end="5">
Item <c:out value="${i}"/><p>
</c:forEach>
</body>
</html>
这将产生以下结果:
Item 1
Item 2
Item 3
Item 4
Item 5
<c:forTokens>例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:forTokens> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:forTokens items="Zara,nuha,roshy" delims="," var="name">
<c:out value="${name}"/><p>
</c:forTokens>
</body>
</html>
这将产生以下结果:
Zara
nuha
roshy
c:param>标签具有以下属性:
属性 | 描述 | 必需 | 默认值 |
name | 在URL中设置的请求参数的名称 | Yes | None |
value | 在URL中设置的请求参数的值 | No | Body |
例子:
如果您需要将参数传递到一个<c:import>标记,使用<c:url>标记创建的URL如下所示:
<c:url value="/index.jsp" var="myURL">
<c:param name="trackingId" value="1234"/>
<c:param name="reportType" value="summary"/>
</c:url>
<c:import url="${myURL}"/>
<c:redirect>标签具有以下属性:
属性 | 描述 | Required | Default |
url | URL重定向用户的浏览器 | Yes | None |
context | /后面的本地Web应用程序的名称 | No | 当前应用 |
例子:
如果您需要将参数传递到一个<c:import>标记,使用<c:url>标记创建的URL如下图所示:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:redirect> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:redirect url="http://www.yiibai.com"/>
</body>
</html>
<c:url>标记具有以下属性:
Attribute | Description | Required | Default |
value | 根URL | Yes | None |
context | /后面的本地Web应用程序的名称 | No | Current application |
var | 变量的名称,暴露处理的URL | No | Print to page |
scope | 变量的作用域暴露处理的URL | No | Page |
例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:url> Tag Example</title>
</head>
<body>
<a href="<c:url value="/jstl"/>">TEST</a>
</body>
</html>