JSLT标签库,是日常开发经常使用的,也是众多标签中性能最好的。这个算是一个java程序员的一个基本功吧。
JSP Standard Tag Library (JSTL) 的规范完成于2002年7月,随后Apache Taglibs Projects在不久的几天中提交了一个参考实现。JSTL 的出现是为了解决程序员一直渴望有一个标准的标签库的需求,同时也为开发JSP带来了很大的便利。
在MVC架构中,由于JSTL的出现,避免了页面中写入java代码,同时让界面美工人员更容易掌握页面。
JSP技术的优势之一在于其定制标记库工具。除了核心JSP标记,如 jsp:include 之外,定制标记库工具使您能够创建唯一的标记来描述以站点或应用程序为导向的操作。一旦您创建了定制标记库(简称 taglib),当您扩展项目或转向另一个项目时您可以重复使用这些标记。您还可以将taglib传递给其它开发人员,从而他们可以在自己的网站上使用,或者在您Web应用程序的其它部分使用。
JSTL 核心标签库标签共有13个,功能上分为4类:
1.表达式控制标签:out、set、remove、catch
2.流程控制标签:if、choose、when、otherwise
3.循环标签:forEach、forTokens
4.URL操作标签:import、url、redirect
使用标签时,一定要在jsp文件头加入以下代码:
%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%
下面是一个小实例,基本上是覆盖了编程的三大结构
1. <c:forEach items="${domainList }" var="item"> 2. <tr> 3. <td align="center" valign="middle">${item["domain"]==null?" ":item["domain"]}</td> 4. <td align="center" valign="middle"><fmt:formatDate value="${item['bind_date']}" pattern="yyyy-MM-dd HH:mm:ss"/></td> 5. <td align="center" valign="middle"> 6. <c:if test="${item['domain']!=null}"> 7. <a href="javascript:;" id="${item['domain']}" class="del"> </a> 8. </c:if> 9. </td> 10. </tr> 11. </c:forEach>