今天随便写了些JSTL的例子,下决心以后决不让我的代码中出现"<%%>"标签
=============================================
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@ page import="test.Test"%>
<%@ page import="java.util.*" %>
<html>
<head>
<title>测试</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%--
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}"/>
<br/>
</c:forEach>
<c:out value="${vname}" default="xxxx"/>
--%>
<c:out value="俺的第一个JSTL程序" />
<Br>
你的浏览器是:
<c:out value="${header['User-Agent']}" />
<c:set var="a" value="裴德万" scope="session"/>
<c:out value="${a}" escapeXml="true"/>
<c:out value="${vname}" default="p" escapeXml="true"/>
<c:set target="${test.Test}" property="name" value="KKMei" var="xx" scope="page" />
<c:set target="${test.Test}" property="age" value="13" var="xx" scope="page" />
<c:out value="${xx[Test.name]}" default="bean->name"/>
<c:out value="${xx[Test.age]}" default="bean->age"/>
<c:forEach var="i" begin="1" end="10">
<c:out value="${i}"/>
<br>
</c:forEach>
<c:if test="${vname=='Peter'}" var="vname" scope="session">
if判断条件测试
</c:if>
<c:set var="k" value="1"/>
<c:if test="${k==1}">
k====1
</c:if>
<c:choose>
<c:when test="${k==1}">
c:when条件判断--==1
</c:when>
<c:when test="${k==2}">
c:when条件判断===2
</c:when>
<c:when test="${k==3}">
c:when条件判断===3
</c:when>
<c:otherwise>
otherwise====0
</c:otherwise>
</c:choose>
<%
Map map=new HashMap();
map.put("A","AAAAAAAAAAAA");
map.put("B","BBBBBBBBBBBB");
map.put("C","CCCCCCCCCCCC");
request.setAttribute("map",map);
List testlist=new ArrayList();
for(int i=0;i<5;i++){
Test test=new Test();
test.setName("p"+String.valueOf(i));
test.setAge(i+10);
testlist.add(test);
}
request.setAttribute("testlist",testlist);
%>
<c:forEach var="xmap" items="${map}" >
new element <c:out value="${xmap.value}"/>
</c:forEach>
<c:forEach var="xlist" items="${testlist}" varStatus="status">
<Br><c:out value="${xlist.name}" /><c:out value="${xlist.age}" /><br>
<c:choose>
<c:when test="${status.count % 2==0}">
list的偶数判定
</c:when>
</c:choose>
</c:forEach>
<c:set var="pname" value="jjkk" scope="page" />
<c:set var="classid" value="kkk" scope="page" />
<c:url value="http://localhost" var="myvar">
<c:param name="name" value="${pname}" />
<c:param name="class" value="${classid}" />
</c:url>
<a href='<c:out value="${myvar}"/>'>ttttt</a>
<fmt:formatNumber value="455558414.63" type="currency" pattern=".000"/>
<jsp:useBean id="now" class="java.util.Date" />
<fmt:formatDate value="${now}" timeStyle="long" dateStyle="long"/><br>
<fmt:formatDate value="${now}" pattern="yyyy-MM-dd hh:mm:ss" timeStyle="full"/>
<br>
<fmt:timeZone value="GMT+1:00">
<fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/>
</fmt:timeZone>
</body>
</html>
===================================
JSTL确实不错...............与struts的标签库结合起来基本上能解决绝大部分的应和...............
JSTL的一个例子
最新推荐文章于 2024-04-27 18:55:55 发布