<jsp-config>标记,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
TagStudy2
</display-name>
<jsp-config>
<taglib>
<taglib-uri>/hello</taglib-uri>
<taglib-location>/WEB-INF/HelloTag.tld</taglib-location>
</taglib>
</jsp-config>
<welcome-file-list>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
从servlet2.4开始,taglib的uri是在标签库描述符中(tld)指定的,就像下面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag
Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>bean</shortname>
<uri>http://jakarta.apache.org/struts/tags-bean</uri>
任何需要使用这个标签库的页面都可以通过下面的页面级指令来引用它。标签库不需要再在web.xml文件中引用:
<%@ taglib
uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean" %>
下面一个表是struts标签的uri:
Table 2-1. Struts 标签库URI | ||
Tag library | Struts 1.1 URI | Struts 1.2 URI |
struts-bean | ||
struts-html | ||
struts-logic | ||
struts-nested | ||
struts-template | 不再包括,被Tiles代替 | |
struts-tiles | ||
struts-bean-el | ||
struts-html-el | ||
struts-logic-el |
sturts标签的可以直接通过uri引用,也可以通过在web.xml中声明再使用。直接通过uri引用,则不再需要tld文件,如果是web.xml的话,灵活性比较大,uri以后改变的话,只需要在web.xml中改变,不用在其他页面中改变。