Last active
August 29, 2015 14:07
-
-
Save precious-ming/6d3625f73a0a787a0a11 to your computer and use it in GitHub Desktop.
jstl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSTL的c:forEach标签(${status.index}) | |
2011-01-19 16:55:34| 分类: Jsp / Servlet | 标签:jstl jsp |举报|字号 订阅 | |
<c:forEach>标签具有以下一些属性: | |
var:迭代参数的名称。在迭代体中可以使用的变量的名称,用来表示每一个迭代变量。类型为String。 | |
items:要进行迭代的集合。对于它所支持的类型将在下面进行讲解。 | |
varStatus:迭代变量的名称,用来表示迭代的状态,可以访问到迭代自身的信息。 | |
begin:如果指定了items,那么迭代就从items[begin]开始进行迭代;如果没有指定items,那么就从begin开始迭代。它的类型为整数。 | |
end:如果指定了items,那么就在items[end]结束迭代;如果没有指定items,那么就在end结束迭代。它的类型也为整数。 | |
step:迭代的步长。 | |
<c:forEach>标签的items属性支持Java平台所提供的所有标准集合类型。此外,您可以使用该操作来迭代数组(包括基本类型数组)中的元素。它所支持的集合类型以及迭代的元素如下所示: | |
java.util.Collection:调用iterator()来获得的元素。 | |
java.util.Map:通过java.util.Map.Entry所获得的实例。 | |
java.util.Iterator:迭代器元素。 | |
java.util.Enumeration:枚举元素。 | |
Object实例数组:数组元素。 | |
基本类型值数组:经过包装的数组元素。 | |
用逗号定界的String:分割后的子字符串。 | |
javax.servlet.jsp.jstl.sql.Result:SQL查询所获得的行。 | |
不论是对整数还是对集合进行迭代, <c:forEach>的varStatus属性所起的作用相同。和var属性一样,varStatus用于创建限定了作用域的变量(改变量只在当前标签体内起作用)。不过,由varStatus属性命名的变量并不存储当前索引值或当前元素,而是赋予javax.servlet.jsp.jstl.core.LoopTagStatus类的实例。该类包含了一系列的特性,它们描述了迭代的当前状态,如下这些属性的含义如下所示: | |
current:当前这次迭代的(集合中的)项。 | |
index:当前这次迭代从0开始的迭代索引。 | |
count:当前这次迭代从1开始的迭代计数。 | |
first:用来表明当前这轮迭代是否为第一次迭代,该属性为boolean类型。 | |
last:用来表明当前这轮迭代是否为最后一次迭代,该属性为boolean类型。 | |
begin:begin属性的值。 | |
end:end属性的值 | |
step:step属性的值 | |
利用varStatus属性: | |
There is a pure way to desplay chekbox with two collums in jsp page. | |
checkboxLists是 checkBoxTO的集合,含有key,value,checke属性。 | |
Java代码 | |
<c:forEach items="${checkboxList}" begin="0" step="2" varStatus="status"> | |
<tr> | |
<td><c:out value="${status.index}"/><input type="checkbox" value='<c:out value="${checkboxList[status.index].key}"/>' | |
<c:if test="${checkboxList[status.index].checked eq true}">checked="checked"</c:if> | |
/><c:out value="${checkboxList[status.index].value}"/> | |
</td> | |
<td><c:if test="${!empty checkboxList[status.index+1]}"><!--判断是否还有下一个纪录,for奇数--> | |
<c:out value="${status.index+1}"/><input type="checkbox" value='<c:out value="${checkboxList[status.index+1].key}"/>' | |
<c:if test="${checkboxList[status.index+1].checked eq true}">checked="checked"</c:if> | |
/><c:out value="${checkboxList[status.index+1].value}"></c:out> | |
</c:if> | |
</td> | |
</tr> | |
</c:forEach> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
参考文章:http://www.cnblogs.com/konbluesky/articles/1925293.html | |
JSP Standard Tag Libraries | |
Formatting and Internationalization | |
Two form input parameters, 'date' and 'isoDate', are URL-encoded in the link leading to this page. 'isoDate' is formatted according to the ISO8601 standard. | |
Formatting of numbers and dates is based on the browser's locale setting. Formatting will change if you switch the default language setting from English to French or German, for example. (The browser needs to be restarted, too.) | |
Library import and parameter capturing: | |
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> | |
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> | |
<fmt:parseDate value="${param.date}" var="date" pattern="yyyy/MM/dd:HH:mm:ss> | |
<fmt:parseDate value="${param.isoDate}" var="isoDate" pattern="yyyyMMdd'T'HHmmss"> | |
The input parameters must match the patterns, or the JSP will thrown an exception. This page does no error handling. | |
Input parameters: | |
Date: 2004/04/01:13:30:00 Java format: Thu Apr 01 13:30:00 CST 2004 | |
isoDate: 20040531T235959 Java format: Mon May 31 23:59:59 CDT 2004 | |
Dates | |
Tag Output | |
Attribute: value; required. Tag has no body. | |
<fmt:formatDate value="${date}" type="both"/> | |
2004-4-1 13:30:00 | |
<fmt:formatDate value="${isoDate}" type="both"/> | |
2004-5-31 23:59:59 | |
Attribute: type; optional. Indicates what to print: date, time, or both. | |
<fmt:formatDate value="${date}" type="date"/> | |
2004-4-1 | |
<fmt:formatDate value="${isoDate}" type="time"/> | |
23:59:59 | |
Attribute: dateStyle; optional. Varies the date format. | |
<fmt:formatDate value="${isoDate}" type="date" dateStyle="default"/> | |
2004-5-31 | |
<fmt:formatDate value="${isoDate}" type="date" dateStyle="short"/> | |
04-5-31 | |
<fmt:formatDate value="${isoDate}" type="date" dateStyle="medium"/> | |
2004-5-31 | |
<fmt:formatDate value="${isoDate}" type="date" dateStyle="long"/> | |
2004年5月31日 | |
<fmt:formatDate value="${isoDate}" type="date" dateStyle="full"/> | |
2004年5月31日 星期一 | |
Attribute: timeStyle; optional. Varies the time format. | |
<fmt:formatDate value="${isoDate}" type="time" timeStyle="default"/> | |
23:59:59 | |
<fmt:formatDate value="${isoDate}" type="time" timeStyle="short"/> | |
下午11:59 | |
<fmt:formatDate value="${isoDate}" type="time" timeStyle="medium"/> | |
23:59:59 | |
<fmt:formatDate value="${isoDate}" type="time" timeStyle="long"/> | |
下午11时59分59秒 | |
<fmt:formatDate value="${isoDate}" type="time" timeStyle="full"/> | |
下午11时59分59秒 CDT | |
Attribute: pattern; optional. Inidcates date/time custom patterns. | |
<fmt:formatDate value="${date}" type="both" pattern="EEEE, MMMM d, yyyy HH:mm:ss Z"/> | |
星期四, 四月 1, 2004 13:30:00 -0600 | |
<fmt:formatDate value="${isoDate}" type="both" pattern="d MMM yy, h:m:s a zzzz/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment