日期:2014-05-16  浏览次数:20316 次

JSP库文件的引用地址
新项目看到jsp页面引入库文件是这样写的
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

大感不惑,之前的jsp页面引入各种库文件,都是把tld文件拷到web-info文件夹下

查了才发现,新写法的原因是:
举例<%@ taglib uri="/struts-tags" prefix="s" %>说明

/struts-tags   是struts标签库,它在/struts2-core-2.1.8.jar/META-INF/struts-tags.tld文件中定义


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
  <description><![CDATA["To make it easier to access dynamic data;
                    the Apache Struts framework includes a library of custom tags.
                    The tags interact with the framework's validation and internationalization features;
                    to ensure that input is correct and output is localized.
                    The Struts Tags can be used with JSP FreeMarker or Velocity."]]></description>
  <display-name>"Struts Tags"</display-name>
  <tlib-version>2.2.3</tlib-version>
  <short-name>s</short-name>
  <uri>/struts-tags</uri>


我们引用时取的就是uri标签中的值.
因为Tomcat等Web服务器会自动加载所有jar文件下的META-INF子目录下的.tld标记定义文件,这也是为什么好多框架不需要把tld文件复制到WEB-INF。