<%@ page language="
java" import="java.util.*,org.
springframework.beans.factory.BeanFactory" pageEncoding="UTF-8"%>
<%@ taglib uri="
http://java.sun.com/
jsp/
jstl/core" prefix="c" %>
<%@ page language="java" import="org.
springframework.core.io.Resource"%>
<%@ page language="java" import="org.
springframework.core.io.ClassPathResource"%>
<%@ page language="java" import="com.zb.entity.NewObj,com.zb.dao.NewObjDAO"%>
<%@ page language="java" import="org.
springframework.beans.factory.
xml.XmlBeanFactory"%>
<%@ page language="java" import="org.
springframework.core.io.FileSystemResource"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>标签测试</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
</head>
<body>
<%
//测试数组
List li=new ArrayList();
li.add("123");
li.add("234");
li.add("456");
request.setAttribute("li",li);
//测试map
HashMap map=new HashMap();
map.put("1","111");
map.put("2","222");
map.put("3","333");
request.setAttribute("map",map);
//测试bean
ClassPathResource resource = new ClassPathResource("../applicationContext.
xml");
BeanFactory factory = new XmlBeanFactory(resource);
NewObjDAO newobjdao=(NewObjDAO)factory.getBean("NewObjDAO");
List nlist=newobjdao.getList();
request.setAttribute("nlist",nlist);
//测试带分隔符的字符串
String movie="好想有个家,爱你一万年,今天,冰雨";
request.setAttribute("movie",movie);
%>
<!-- 绑定ArrayList -->
<c:forEach var="li" items="${li}">
${li}<br><br>
</c:forEach>
<!-- 绑定map -->
<c:forEach var="li" items="${map}">
${
li.key} ${
li.value}<br><br>
</c:forEach>
<!-- 绑定beanlist -->
<c:forEach var="li" items="${nlist}">
${
li.id} ${
li.name}<br><br>
</c:forEach>
<!-- 绑定String -->
<c:forEach var="li" items="${movie}">
${li}<br><br>
</c:forEach>
<!-- forTokens绑定String,并指定分隔符 -->
<c:forTokens var="li" items="${movie}"
delims=",">
${li}<br><br>
</c:forTokens>
<!-- if与varStatus的结合,first代表是否是第一个迭代元素,还有last,count,index等,其中count代表当前这次迭代从 1 开始的迭代计数 -->
<c:forEach var="li" items="${nlist}"
varStatus="ls">
<c:if test="${
ls.first}">
${li.id} ${li.name} ${li.addtime }<br><br>
</c:if>
${li.id} ${li.name}<br><br>
</c:forEach>
<!--只有第一个元素才显示"添加日期" -->
</body>
</html>
转载于:https://www.cnblogs.com/xinxinbb/archive/2009/08/11/1543742.html