JSTL及其POM配置

来源:互联网 发布:小学教师网络研修日志 编辑:程序博客网 时间:2024/06/15 18:31

一、前言

  JSTL(JSP Standard Tag Library,JSP标准标签库)是一个不断完善的开放源代码的JSP标签库,是由apache的jakarta小组来维护的。然而jakarta有很多子项目如Tomcat、Lucene升级为Apache子项目,当前Jakarta无剩余的子项目,Jakarta项目于2011年12月21日退役。

  我需要利用Maven构建项目,此时需要使用到JSTL,但是我看到网上的一些教程,都是复制jar包到编译路径下。而这些jar包我却在Maven仓库中查不到,很是郁闷,而且查到JSTL的POM配置有些怪异,因此在这里进行整理一下。

官网:http://tomcat.apache.org/taglibs/ 

JSTL与Servlet&JSP版本对照图(官网)


JSTL 1.0&1.1 官网下载地址:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/

JSTL 1.2 官网下载地址:http://tomcat.apache.org/download-taglibs.cgi

  分析:我发现1.0与1.1没有在Maven仓库中存在,而且其使用方式都是将jstl.jar与standard.jar添加到编译路径下,并将tld文件夹中的文件(或者包含文件夹)复制到/WEB-INF,然后配置web.xml文件;而1.2就不一样了。再往下我是对各个版本README文件进行分析,如果没兴趣可以直接看第二段落。

1.1 JSTL 1.0

README文件(部分)

The following two files are standalone web applications (WARs) that aredesigned to work out of the box in order to help you learn JSTL:   standard-doc.war                Documentation   standard-examples.war           Simple examples of JSTL tagsTo use this distribution with your own web applications, simply copy the JARfiles in the 'lib' directory to your application's WEB-INF/lib directory.Then, import JSTL into your pages with the following directives:  CORE LIBRARY    EL:  <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>    RT:  <%@ taglib prefix="c_rt" uri="http://java.sun.com/jstl/core_rt" %>  XML LIBRARY    EL:  <%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>    RT:  <%@ taglib prefix="x_rt" uri="http://java.sun.com/jstl/xml_rt" %>  FMT LIBRARY     EL:  <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>    RT:  <%@ taglib prefix="fmt_rt" uri="http://java.sun.com/jstl/fmt_rt" %>  SQL LIBRARY    EL:  <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>    RT:  <%@ taglib prefix="sql_rt" uri="http://java.sun.com/jstl/sql_rt" %>COMPATIBILITY
  前面讲的是这两个*.war文件都是一个示例项目,可以帮助我们学习JSTL。紧随其后就是使用方式,如果要在web应用中使用,我们只需要简单拷贝lib文件夹的jar文件到web应用的WEB-INF/lib目录下,然后在你使用JSTL的页面导入下面的指令。

README(部分)

COMPATIBILITYThe 1.0 version of the Standard Taglib has been tested under Tomcat 4.0.4and should work in any compliant JSP 1.2 container.  To use thisdistribution on earlier versions of Tomcat (such as 4.0.3), however, youmay need to work around a container bug that prevents JAXP 1.2 classesfrom loading successfully.To do this, you should to replace the JAXP 1.2 JAR files included withthis distribution (in the 'lib' directory) with older XML-related JARfiles. To obtain these older, unsupported libraries, you can download thefile namedjakarta-taglibs-standard-oldxml-compat.tar.gzorjakarta-taglibs-standard-oldxml-compat.zipfrom the same directory from which you downloaded this distribution(http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/).Once you have obtained these files, install them (crimson.jar andxalan.jar) into your WEB-INF/lib directory in place of the following filesfrom this distribution:  jaxp-api.jar, dom.jar, sax.jar, xercesImpl.jar,and the newer xalan.jar.Note that upgrading to Tomcat 4.0.4 is recommended and that we providethese older libraries as a temporary convenience for those who have notyet upgraded.
  这部分大体上说的是JSTL需要运行在Tomcat 4.0.4以上以及JSP1.2容器上,如果低于这些配置应该如何处理的方法,因为这些没啥意义就不在解释了。

1.2 JSTL 1.1

README文件(部分)

LIBRARY DEPENDENCIESThis version of the Standard Tag Library has the following runtimedependencies:   1. Dependencies provided by the JSP 2.0 container:      - Servlet 2.4      - JSP 2.0   2. Dependencies provided in newer J2SEs (1.4.2 and higher)      - JAXP 1.2       - Xalan 2.5       - JDBC Standard Extension 2.0Since all of the dependencies in (2) are included in Sun'sdistribution of J2SE 1.4.2 (and higher), this is therefore the J2SEversion of choice to use the standard tag library.If the java platform under which you run your JSP container does notprovide these dependencies, they must be made available either globallyto all web-applications by your container, or individually within theWEB-INF/lib directory of your web-application.For convenience, these jar files have been included in directory lib/old-dependencies of this distribution (assuming the build processof this distribution included them). If you would like to downloadthese jar files yourself, instructions on where you can get them are included below.

  这部分说的是JSTL 1.1的依赖,其Java版本是1.4及其以上的,Servlet 2.4和JSP 2.0。如果容器没有提供这些依赖,则下面就是叙述这些依赖的配置方式,具体的jar包配置省略了,当前的容器肯定都支持了。

USING THE STANDARD TAG LIBRARYTo use this distribution with your own web applications, simply copy the JARfiles in the 'lib' directory (jstl.jar and standard.jar) to your application's WEB-INF/lib directory (add the other dependencies as well if your runtimedoes not already provide them). Then, import JSTL into your pages with the following directives:  CORE LIBRARY    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  XML LIBRARY    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>  FMT LIBRARY     <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  SQL LIBRARY    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>  FUNCTIONS LIBRARY    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  这部分说的是其使用方式,与1.0大致相同,就是拷贝lib文件夹下的jar包jstl.jar和standard.jar这两个包到应用的WEB-INF/lib目录下,然后在你需要使用JSTL的页面导入下面的指令。
COMPATIBILITYThe 1.1 version of the Standard Taglib has been tested under Tomcat 5.0.3and should work in any compliant JSP 2.0 container.
  这部分说的是JSTL需要运行在Tomcat 5.0.3以上,或者任意JSP 2.0容器。

1.3 JSTL 1.2

README(部分)

LIBRARY DEPENDENCIESThis version of the Standard Tag Library has the following runtimedependencies:   1. Dependencies provided by a JSP 2.1 container:      - Java 1.5 or later      - Servlet 2.5 or later      - JSP 2.1 or later   2. Additional dependencies      - The XML tag library requires Apache Xalan 2.7.1 or later
  这部分说的是JSTL1.2需要运行在Java1.5及其以上版本,Servlet 2.5及其以上版本以及JSP 2.1及其以上版本,并且XML的版本需要是2.7及其以上版本。

ADD DEPENDENCIES TO A WEB APPLICATIONTo use this distribution with your own web applications, add the following JARfiles to the '/WEB-INF/lib' directory of your application:   - taglibs-standard-spec-1.2.5.jar   - taglibs-standard-impl-1.2.5.jar   - taglibs-standard-jstlel-1.2.5.jar   - xalan-2.7.1.jar   - serializer-2.7.1.jarIf you do not use JSTL 1.0 tags then the "taglibs-standard-jstlel" JAR may beomitted. If you do not use the XML library, then the Apache Xalan dependenciesmay also be omitted.If you build you application with Maven, add the following dependencies toyour pom.xml file:    <dependency>      <groupId>org.apache.taglibs</groupId>      <artifactId>taglibs-standard-spec</artifactId>      <version>1.2.5</version>    </dependency>    <dependency>      <groupId>org.apache.taglibs</groupId>      <artifactId>taglibs-standard-impl</artifactId>      <version>1.2.5</version>    </dependency>
  这部分说的是JSTL添加依赖到Web应用,需要添加上面列举的5个文件到/WEB-INF/lib中,其中最后的两个jar包是Apache Xalan 2.7.1依赖包。如果你不使用JSTL1.0则taglibs-standard-jstlel-*.jar可以忽略,如果你不使用XML库,那么Apache Xalan依赖也可以省略。
  如果你是用Maven构建你的应用,只需要添加以下内容到pom.xml中:

<dependency>  <groupId>org.apache.taglibs</groupId>  <artifactId>taglibs-standard-spec</artifactId>  <version>1.2.5</version></dependency><dependency>  <groupId>org.apache.taglibs</groupId>  <artifactId>taglibs-standard-impl</artifactId>  <version>1.2.5</version></dependency>
README(部分)

USING JSTL TAGS FROM A JSPThe JSTL tag library can be imported into your pages with the following directives:  CORE LIBRARY    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  XML LIBRARY    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>  FMT LIBRARY     <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  SQL LIBRARY    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>  FUNCTIONS LIBRARY    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  这部分说的是在JSP中使用JSTL的方法,就是在页面中添加以上tag。

README(部分)

COMPATIBILITYThe 1.2 version of the Standard Taglib has been tested using Tomcat 7.0.57and should work in any compliant JSP 2.1 (or later) container.In version 1.2.3 and later, the XML libraries enable FEATURE_SECURE_PROCESSINGwhen parsing and transforming. The system property  org.apache.taglibs.standard.xml.accessExternalEntitycan be used to further restrict the protocols over which external entities canbe resolved. When a SecurityManager is enabled this will, by default, allowaccess to no protocols. Permission must be granted to the taglibs-standard-impllibrary to read this property.  permission java.util.PropertyPermission "org.apache.taglibs.standard.xml.accessExternalEntity", "read";


二、JSTL安装配置

2.1 JSTL 1.1 配置

  我们首先要下载jakarta-taglibs-standard-1.1.*.zip文件,然后解压到任意目录,将lib目录下的jstl.jar和standard.jar两个包拷贝到Web项目的/WEB-INF/lib目录下,并且将其tld文件夹也拷贝到/WEB-INF目录下。

注意:环境不能低于Servlet 2.4和JSP 2.0
  然后就可以在JSP页面引入JSTL标签库,引入方式如下:

CORE LIBRARY  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>XML LIBRARY  <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>FMT LIBRARY   <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>SQL LIBRARY  <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>FUNCTIONS LIBRARY  <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
使用哪个标签库,就引入哪个标签库即可。

2.2 JSTL 1.2 配置

运行环境依赖:

  1.  JSP 2.1 容器依赖支持:
    • Java 1.5 or later
    • Servlet 2.5 or later
    • JSP 2.1 or later
  2. 额外依赖
    • The XML tag library requires Apache Xalan 2.7.1 or later
Apache Xalan 2.7.1
  To address performance issues with XSLT processing, this version relies on
implementation specific functionality from Apache Xalan. The following
libraries should be included in the classpath for your application:
  • xalan-2.7.1.jar
  • serializer-2.7.1.jar
JSTL 1.2 与以前不同的是jar包都是分离的,其主要的jar包包含如下几个:

  • taglibs-standard-spec-1.2.5.jar
  • taglibs-standard-impl-1.2.5.jar
  • taglibs-standard-jstlel-1.2.5.jar
  • xalan-2.7.1.jar
  • serializer-2.7.1.jar
  其中最后的两个jar包是Apache Xalan 所需要的依赖,如果我们不适用JSTL 1.0 则taglibs-standard-jstlel这个jar包也不需要,因此主要的两个jar包taglibs-standard-spec和taglibs-standard-impl拷贝到Web项目的/WEB-INF/lib目录下,这样就可以了,无须再导入tld文件了。如果使用Maven构建Web项目则只需配置这两个jar包即可,配置如下:

<dependency>  <groupId>org.apache.taglibs</groupId>  <artifactId>taglibs-standard-spec</artifactId>  <version>1.2.5</version></dependency><dependency>  <groupId>org.apache.taglibs</groupId>  <artifactId>taglibs-standard-impl</artifactId>  <version>1.2.5</version></dependency>
  使用方式与1.1类同,在使用JSTL的页面添加如下tag即可:

CORE LIBRARY  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>XML LIBRARY  <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>FMT LIBRARY   <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>SQL LIBRARY  <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>FUNCTIONS LIBRARY  <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

&#8195&#8195

博客发表时间:2017年3月10日02:20:13

最后修改时间:2017年3月10日11:30:57

********************************************************************************结束语********************************************************************************************
  我在写这篇博客的时候也是一名初学者,有任何疑问或问题请留言,或发邮件也可以,邮箱为:fanxiaobin.fxb@qq.com,我会尽早的进行更正及更改。
在我写过的博客中有两篇博客是对资源的整理,可能对大家都有帮助,大家有兴趣的话可以看看!!
下载资料整理——目录:http://blog.csdn.net/fanxiaobin577328725/article/details/51894331
  这篇博客里面是我关于我见到的感觉不错的好资源的整理,里面包含了书籍及源代码以及个人搜索的一些资源,如果有兴趣的可以看看,我会一直对其进行更新和添加。
优秀的文章&优秀的学习网站之收集手册:http://blog.csdn.net/fanxiaobin577328725/article/details/52753638
  这篇博客里面是我对于我读过的,并且感觉有意义的文章的收集整理,纯粹的个人爱好,大家感觉有兴趣的可以阅读一下,我也会时常的对其进行更新。
********************************************************************************感谢********************************************************************************************

0 0
原创粉丝点击