1.在JSP页面中引入sun的核心标签库
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
2.在JSP页面中引入sun的函数标签库
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
3.判断是否为空
<c:if test="${!empty map}">
</c:if>
4.判断长度大于0
<c:if test="${fn:length(map)>0}">
</c:if>
注:fn:length(obj),对于空对象也会返回0
5.例子:将request传入的hashmap显示在表格中
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="java.util.HashMap,java.util.Iterator"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %><!-- 引入sun的核心标签库 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%><!-- 引入sun的函数标签库 -->
<!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=utf-8">
<title>显示jsp传递的参数-使用标签库</title>
</head>
<body>
<center><h1>传递的参数</h1></center>
<hr/>
<c:choose>
<c:when test="${fn:length(requestScope.paramMap)>0}">
<table border="1">
<tr><th>参数名</th><th>参数值</th></tr>
<c:forEach items="${requestScope.paramMap}" var="map">
<tr><td>${map.key}</td><td>${map.value}</td></tr>
</c:forEach>
</table>
</c:when>
<c:otherwise>
<c:out value="没有在request中传递paramMap属性"/><br/>
<p>paramMap大小为:${fn:length(requestScope.paramMap)}</p>
</c:otherwise>
</c:choose>
</body>
</html>
posted on 2012-08-06 15:30
小桥流水人家 阅读(12193)
评论(1) 编辑 收藏 所属分类:
sun-jstl