<%@ page language="java" import="java.util.*,com.saly.domain.Person" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cn" lang="cn">
<html>
<head>
<title>JSTL</title>
</head>
<body>
<%
request.setAttribute("data",null);
%>
<br/>----------------------c:out-------------------------<br/>
<c:out value="${data}" default="范春" escapeXml="true"></c:out>
<br/>-----c:set 可以给各个域 javabean Map集合-------------------------<br/>
<c:set var="data" value="xxx" scope="page"></c:set>
${data}<br>
<%
Map map = new HashMap();
request.setAttribute("map",map);
%>
<c:set property="dd" value="mapsaly" target="${map}"></c:set>
${map.dd}<br/>
<%
Person p = new Person();
request.setAttribute("person",p);
%>
<c:set value="salyfan" target="${person}" property="name"></c:set>
${person.name}
<br/>----------------------c:catch捕获异常-------------------------<br/>
<c:catch var="myexc">
<%
int x = 1/0;
%>
</c:catch>
${myexc.message}
<br/>----------------------c:if-------------------------<br/>
<c:if var="var" test="${user==null}" scope="page">
c:if <br/>
</c:if>
${var}
<br/>----------------------c:foreach-------------------------<br/>
<%
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add("ddd");
list.add("eee");
list.add("fff");
request.setAttribute("list",list);
%>
<c:forEach var="str" items="${list}">
<c:out value="${str}"></c:out><br/>
</c:forEach>
<c:forEach var="num" begin="1" end="9" step="4" >
${num}
</c:forEach>
<style>
tr:hover{background-color:red;}
</style>
<table border="1" width="20%">
<c:forEach var="str" items="${list}" varStatus="status">
<tr class="${status.count%2==0?'even':'odd'}">
<td>
${str}
</td>
</tr>
</c:forEach>
</table>
<br/>----------------------c:url-------------------------<br/>
<c:url var="url" value="/Tld/xx">
<!--可以传递参数,并对 中文进行URL编码 -->
<c:param name="name" value="中国"></c:param>
</c:url>
<a href="${url}">购买</a><br />
<!-- 可以直接返回工程路径 -->
<a href="<c:url value="/index.jsp"/>">点</a>
<br/>----------------------c:forTokens用来字符串分割-------------------------<br/>
<%
pageContext.setAttribute("data","aa,bb,cc,dd,ee,ff");
%>
<c:forTokens var="ss" items="${data}" delims="," >
${ss}<br/>
</c:forTokens>
</body>
</html>