c.tld文件下放的就是jstl核心标签。
<c:out value = "" default = "" escapeXml = ""/>
value:要输出的值
defaule:要输出的值为空时,输出默认值
escapeXml:是否转义后输出
向域中存数据:
<c:set value = "" var = "" scope = ""/>
向map集合中存数据:
<c:set property = "" value = "" target = "map"/>
向javaBean中存数据
<c:set property = "" value = "" target = "bean"/>
删除域中的值:
<c:remove var = "" scope = ""/>
scope :page, request, session, application
<c:catch var = "exception" >
</c:catch>
将代码卸载catch标签中,出现异常之后,会将异常对象以var值为关键字存储在域中,可以使用${exception.message}来获取异常信息
<c:if var = "" test = "" scope = "">
</c:if>
var,scope:将test条件的返回结果(true,false)以var为关键字存储在scope域中。
<c:choose>
<c:when test = "">
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
相当于if....else
迭代集合
<c:forEach var = "" items = "">
</c:forEach>
打印页码条
<c:forEach var = "" begin = "1" end = "9" step = "1">
</c:forEach>
从1开始,到9结束,步长为1
var:将数据以var为key保存到域中。
varstatus:存放迭代信息,如这是第几次迭代。
使用varstatus实现间色表格
<style>
.odd{background-color}
.even{background-color}
</style>
<table border = "1" width = "20%">
<c:forEach var = "str" items = "${list}" varstatus = "status">
<tr class = "${status.count == 0 ? 'event' : 'odd'}">
<td>${str}</td>
</rt>
</c:forEach>
</table>
<c:url var = "" value = "day/a/b">
会将value的值以var值为key存储在域中。第一次访问的时候,会进行url重写,在value后面跟上session的id,防止用户禁用cookie。下次访问发现用户没有禁用cookie,则不进行url地址重写。
如果和跟var属性,标签将会把地址输出给浏览器,并自动在前面加上项目根目录.
<a href = "<c:url value = "/index.jsp/">">测试</a>
建议使用的时候使用var属性。
使用param可以在url地址后面跟参数,参数值如果为中文,则会自动进行url编码。
<c:url var = "" value = "">
<c:param name = "" value = ""/>
</c:url>
<%
request.setAttribute("data", "aa,dd,ss,ff");
%>
<c:forTokens var = "value" items = "${data}" delims = ",">
${value}
</c:forTokens>