什么是 JSTL 强制 Jars

What are JSTL mandatory Jars

我是新手,刚开始学习Java。从jstl这个标签开始,我对jstl有了很多了解。

我使用 IDE(eclispe mars) 通过添加一个简单的 jsp 页面来创建动态 Web 项目,然后将 war 导出到 tomcat7 的 Web 应用程序文件夹。我对 jstl 强制 jar 的依赖性做了一些测试。

我的核心项目文件是:

web.xml: 

  <web-app xmlns:xsi="http:....... version="3.0">   //use servlet 3.0

index.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jstl Tag Lib</title>
</head>
<body>
<h2>2+2=${2+2}</h2> //this line works, el is a part of jsp.

//below lines work fine if there are proper jstl jars.
<c:set var="salary" scope="session" value="${2000*2}" />
salary:<c:out value="${salary}" />
</body>
</html>

在WEB-INF/lib/文件夹中,我有3种罐子,这3组都可以。

1) 仅包含:

jstl-1.2.jar

哪个组织提供的?阿帕奇 tomcat?

2) 仅包含:

javax.servlet.jsp.jstl-api-1.2.1.jar
javax.servlet.jsp.jstl-1.2.4.jar

在这里,我有一个问题:这两个jar有什么区别?

3) 仅包含:

taglibs-standard-impl-1.2.5.jar
taglibs-standard-compat-1.2.5.jar
taglibs-standard-jstlel-1.2.5.jar
taglibs-standard-spec-1.2.5.jar

Thoes jar 下载自 http://tomcat.apache.org/download-taglibs.cgi 在这里,我有一个问题:三个罐子有什么区别? 因为不知道有什么区别,我把这三个jar放到了lib文件夹下,但是发现taglibs-standard-impl.*.jar在runnnig的时候是必须的。

我想了一晚上的问题,我意识到也许答案就在罐子旁边。问题的最后一部分,关于 4 个 apache tomcat 罐子,来自 link, there are 2 readme text files(Source README, Binary README)

它说:

There are three primary sub-modules:

    spec            <-- contains Apache's implementation of the API classes
    impl            <-- contains the implementation of tags from the 1.1
                        namespace http://java.sun.com/jsp/jstl/*
    jstlel          <-- contains the implementation of tags from the 1.0
                        namespace http://java.sun.com/jstl/* and uses the
                        original JSTL 1.0 version of EL

In addition, the following modules provide supporting functionality
    build-tools     <-- build support such as checkstyle rules
    compat          <-- contains the implementation of tags from the 1.0
                        namespace but uses the JSP container's implementation
                        of EL (which will be 2.1 or later).

二进制自述文件:

This version of the Standard Tag Library has the following runtime
dependencies:

   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

---
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

---------------------------------------------------------------------------
ADD DEPENDENCIES TO A WEB APPLICATION

To use this distribution with your own web applications, add the following JAR
files 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.jar

If you do not use JSTL 1.0 tags then the "taglibs-standard-jstlel" JAR may be
omitted. If you do not use the XML library, then the Apache Xalan dependencies
may also be omitted.

If you build you application with Maven, add the following dependencies to
your 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>

我也用jd-gui反编译了jar,然后在taglibs-standard-impl-1.2.5.jar里找到了一些类,它们的基础类在taglibs里-标准规范-1.2.5.jar。

同样使用反编译的方法,我发现,

jstl-1.2.jar是一个单独的jar,但是jar里面有两个主要的包。 - 1) org.apache.taglibs.standard - 2) javax.servlet.jsp.jstl

javax.servlet.jsp.jstl-1.2.4.jar 和 javax.servlet.jsp.jstl-api-1.2.1.jar 是另一个组 jar。

每个jar里面只有一个main package,在javax.servlet.jsp.jstl-1.2.4.jar中是org.apache.taglibs.standard namespace,在[=]中是javax.servlet.jsp.jstl namesapce 37=]-api-1.2.1.jar。所以我们可以说两个罐子的组合等于 jstl.jar

情况与apache tomcat jars组类似。区别在于 apache tomcat 实现将更多 类 分成 3 或 4 个不同的 jar 文件。

到目前为止,我可以说我了解那些 apache tomcat jar 的大部分基本用法。