<c:forTokens var="value" items="a-b-c-d" delims="-">
${value}<br>
</c:forTokens>
JSTL函数标签库,用来处理字符串,头标签描述
<%@ taglib uri=”http://java.sun.com/jsp/jstl/functions“ prefix=”fn”%>
例如
${requestScope.value}<br>
${fn:length(requestScope.value)}<br>
${fn:contains(requestScope.value, "c")}<br>
${fn:indexOf(requestScope.value, "c")}<br>
JSTL格式化标签库,用来处理日期,实现格式化,头标签描述
<%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt“ prefix=”fmt”%>
例如
<fmt:formatDate value="${requestScope.date}" pattern="yyyy-MM-dd kk:mm:ss"></fmt:formatDate>
部分购物小系统代码用EL、JSTL代替示例
<%
ArrayList<Commodity> commodityArrayList=(ArrayList<Commodity>)request.getAttribute("commodityArrayList");
for(Commodity commodity:commodityArrayList){
out.write("<tr>");
out.write("<td><input type=\"checkbox\" name=\"cid\" value=\""+commodity.getCid()+"\"></td>");
out.write("<td>"+commodity.getCname()+"</td>");
out.write("<td>"+commodity.getCbalance()+"</td>");
out.write("</tr>");
}
%>
<c:forEach var="commodity" items="${requestScope.commodityArrayList}">
<tr>
<td><input type="checkbox" name="cid" value="${commodity.cid}"></td>
<td>${commodity.cname}</td>
<td>${commodity.cbalance}</td>
</tr>
</c:forEach>
<%
HashMap<Commodity, Integer> shoppingCart=(HashMap<Commodity, Integer>)session.getAttribute("shoppingCart");
Set<Commodity> keys= shoppingCart.keySet();
Iterator<Commodity> it= keys.iterator();
while (it.hasNext()){
Commodity c= it.next();
Integer count=shoppingCart.get(c);
out.write("<tr>");
out.write("<td>"+c.getCname()+"</td>");
out.write("<td>"+c.getCbalance()+"</td>");
out.write("<td>"+count+"</td>");
out.write("</tr>");
}
%>
<c:forEach var="map" items="${sessionScope.shoppingCart}">
<tr>
<td>${map.key.cname}</td>
<td>${map.key.cbalance}</td>
<td>${map.value}</td>
</tr>
</c:forEach>