JSTL(JavaServer Pages Standard Tag Library)初步
2009-06-17 15:47
381 查看
我对JSTL的认识
struts也有自己的标签库,与JSTL功能差不多,但由于要依赖struts框架,所以不如JSTL用的多,JSTL是sun开发的,只要支持Servlet2.4规范就可以使用。JSTL是和EL一起使用的,EL主要实现了取数据和表达式计算的功能,那JSTL的主要功能就是运算流程控制了。JSTL的内容
JSTL包括循环标签,流程控制标签,操作XML文档的标签,格式化标签,使用sql语句的标签和函数标签。分别对应的URI为:[b]JSTL URI 前缀
[/b]
核心 http://java.sun.com/jsp/jstl/core c
XML http://java.sun.com/jsp/jstl/xml x
国际化 http://java.sun.com/jsp/jstl/fmt fmt
sql http://java.sun.com/jsp/jstl/sql sql
函数 http://java.sun.com/jsp/jstl/functions fn
JSTL的使用
与其他所有的标签库一样,使用JSTL需要在jsp页面中加入taglib指令。如:<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
JSTL与EL的结合
在JSP页面中(当然也包括JSTL标签中啦)EL表达式是要放到”“中的。我猜是因为对EL的解析比较早吧。应该是容器在将jsp转为Servlet的时候会首先对EL进行解析,因为EL的语法看起来有些怪,明显不是jsp那一套东西。
JSTL核心标签库
变量支持标签
<c:set>set标签可以设置一个Scope中变量的值,如果这个变量不存在,那么就创建这个变量。
<c:remobe>
很容易猜到,这个的意思是将那个变量的删掉。
流程控制标签
条件标签
<c:if>这个标签实现了if语句的功能,如:
<c:if test = "${empty(sessionScope.testValue)}">... ...</c:if>
因为if要和c:一起来表示标签,因此用test来代替if来表示判断语句。如果test=后面为TRUE,则执行<c:if></c:if>之
间的语句。
<c:choose>
<c:when test=”“></c:when>
<c:otherwise></c:otherwise>
</c:choose>
这个结构相当于:
if(){
}else{
}
迭代标签
<c:forEach >示例:<c:forEach items = "${paramValues.Habit} var = "habit"">
${habit}
</c:forEach>
<c:forEach>标签支持很多集合类型,如java.util.Collection,java.util.Map,java.util.Iterator何java.util.
Enumeration。如果字符串是由逗号分隔的一组值,forEach也支持将其分割。如:
<c:forEach items ="Monday, Tuesday, Wednesday, Thursday, Friday" var="week">
${week}
</c:forEach>
<c:forTokens>
将字符串按照指定的分割符分割成若干个子串。如:
<c:forTokens ites="Monday,-Tuesday, Wednesday, Thursday, Friday" var="week" delims=",-">
URL标签
<c:import>包括静态内容:
<c:import url="/jsp/index.txt" context = "/other">
包括动态内容:
<c:import url = "http://java.sun.com">
<c:param name = "num" value="12">
</c:import>
这个式子等价于:http://java.sun.com?num=12
<c:redirect>
将客户端的请求重定向到其它文件。redirect也可以使用param标签向转向的文件传递参数。
<c:url>
能动态地产生一个网址。
国际化标签库
<fmt:requestEncoding>用来设定字符串编码,和ServletRequest.setCharacterEncoding()方法相同。如
<fmt:requestEncoding value = "gb2312">
<fmt:formatNumber>
例子:<fmt:formatNumber value="${book.price}" type = "currency">
<fmt:formatDate>
例子:<fmt:formatDate value = "${now}">
相关文章推荐
- JSP标准标签库 JSTL(JavaServer Pages Standard Tag Library)
- JSTL(JSP标准标签库/JavaServer Pages Standard Tag Library)
- JSTL(Java Server Pages Standard Tag Library)标签函数库
- JavaServer Pages Standard Tag Library(jstl1.1)标签函数库(待续)
- JavaServer Pages Standard Tag Library
- Web Tier to Go With Java EE 5: Summary of New Features in Java Standard Tag Library (JSTL) 1.2
- Jave Web JSTL(JspServer Pages Standdard Tag Library:JSP标准标签库)
- java.lang.ClassCastException: org.apache.taglibs.standard.tlv.JstlCoreTLV cannot be cast to javax.servlet.jsp.tagext.TagLibraryValidator
- JavaServer Pages Standard Tag Libraries
- 【Jstl】java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
- eclipse提示Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/functions"
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/
- MyEclipse 出错提示 Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
- JSP Standard Tag Library (JSTL)介绍
- maven Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core
- org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.Jstl
- JSP出现的错误为java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
- cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core
- Can not find the tag library descriptor for "http://Java.sun.com/jsp/jstl/core"