读书人

Jsp tag file例证以及说明

发布时间: 2012-12-28 10:29:04 作者: rapoo

Jsp tag file例子以及说明
简介

Jsp2.0后,实现tag的方式除了taglib(TLD)的方式外,还可以通过定义tag文件来代替taglib类。tag file一般放在/WEB-INF/tags目录或者其子目录,需要在jsp文件中指定uri。


参考

例子来源

http://today.java.net/pub/a/today/2003/11/14/tagfiles.htmlhttp://today.java.net/pub/a/today/2003/11/25/tagfiles.html


说明

注:jsp和tag file在Tomcat7下编译。


例子1 将tag file作为内容直接引入

firstTagTest.jsp

<%@ tag import="java.util.Date" import="java.text.DateFormat"%><%@ variable name-given="longDate" %><%@ variable name-given="shortDate" %><%  Date now = new Date(System.currentTimeMillis());  DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);  DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);  jspContext.setAttribute("longDate", longFormat.format(now));  jspContext.setAttribute("shortDate", shortFormat.format(now));%><jsp:doBody/>//说明要让jsp编译的java类回调,所以jsp编译的java类有Helper类封装JspFragment(即tag编译后的java类)




1楼liu332355559昨天 23:14
很高级的样子

读书人网 >JavaScript

热点推荐