了解谁提供了servlet-api.jar,它是web容器还是Java EE下载的一部分 [英] Understanding who provides servlet-api.jar, is it web-container or part of Java EE download

查看:160
本文介绍了了解谁提供了servlet-api.jar,它是web容器还是Java EE下载的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要了解编译servlet所需的serlvet-api.jar。

I need understanding about the serlvet-api.jar which is needed to compile a servlet.

我正在构建一个简单的servlet,如下所示:

I am building a simple servlet, like this:

import javax.servlet.*;
import javax.servlet.http.*;

public class FirstServlet extends HttpServlet {
    // Remaining code here
}

我知道我们需要servlet-api.jar文件来编译这个简单的servlet,如下所示:

I know that we need servlet-api.jar file to compile this simple servlet, like this:

javac -classpath /path/where/jar/is/servlet-api.jar

现在我怀疑了从这里开始:

Now my doubts starts here:


  1. 什么是servlet-api.jar?

  2. 谁提供这个jar?

  3. 每个web容器都提供这个jar,例如Tomcat,Jboss,glassfish吗?并且每个供应商是否为构建这个简单Servlet所需的jar提供了相同的名称。

  4. 当我们下载Java EE时,这个jar是下载的一部分吗?或者我们是否将此文件作为Web容器的一部分?

  5. 考虑这种情况:

  1. What is servlet-api.jar?
  2. Who provides this jar?
  3. Does each web-container provide this jar e.g., Tomcat, Jboss, glassfish? And does each vendor provide the "same name" to the jar that is needed to build this simple Servlet.
  4. When we download Java EE , is this jar part of download? OR do we get this file as part of web container?
  5. Consider this situation:

假设我们编译/构建使用Tomcat的简单servlet(即构建servlet所需的tomcat版本的jar)并创建.war文件。我们可以在其他供应商的容器中部署战争吗?

Suppose we compile / build the simple servlet using Tomcat (i.e tomcat's version of jar needed to build the servlet) and create a .war file. Can we then deploy the war in some other vendor container?


推荐答案

它是什么?

servlet-api jar是一个包含Servlet API规范的接口和类的库。 servlet-api jar只包含Servlet规范的接口(API),因此您可以使用它来开发Web应用程序。

The servlet-api jar is a library which contains the interfaces and classes of the Servlet API specification. The servlet-api jar contains only the interface (the API) of the Servlet Specification, so you can use it to develop your web application.

你在哪里可以得到它?

它在以下链接中提供:

http://download.oracle.com/otndocs/jcp/servlet-3.0 -fr-eval-oth-JSpec /

包含/捆绑的地方

Servlet-api.jar是Java EE下载的一部分,因此您可以开发Web应用程序(如果Java EE,则无法编译 FirstServlet 类不包含它。)

Servlet-api.jar is part of the Java EE download so you can develop your web applications (you could not compile your FirstServlet class if the Java EE would not contain it).

Servlet容器(如Tomcat,JBoss,GlassFish等)也包含servlet-api.jar否则它们将无法运行你的Web应用程序,而且它们还包含作为Servlet API一部分的接口的实现。

Servlet containers (like Tomcat, JBoss, GlassFish etc.) also contain the servlet-api.jar else they would not be able to run your web application, and moreover they also contain the implementation of the interfaces that are part of the Servlet API.

名称虽然并不总是相同,它甚至可能不作为一个单独的jar存在,Servlet API类可能会捆绑在另一个jar中。

The name is not always the same though, and it might not even exist as a separate jar, the Servlet API classes might be bundled in another jar.

但是你可以单独下载如果您只想为Servlet容器开发Web应用程序,或者您想创建/编写自己的Servlet API实现,那么jar文件只包含Servlet API。请看这里:

You can however download a separate jar file containing only the Servlet API if you just want to develop a web application for a Servlet container, or if you want to create/write your own Servlet API implementation. Look at here:

http://download.oracle.com/otndocs/jcp/servlet-3.0-fr-eval-oth-JSpec/

可移植性

如果您拥有Servlet API,无论它来自何处,您都可以编译您的Web应用程序。编译Web应用程序后,您可以选择将其打包到WAR文件(WAR = Web ARchive)中,该文件只是一个包含静态文件的zip文件,编译的java类和配置文件,如 web.xml 等。您将能够在任何Servlet容器中运行已编译的Web应用程序(但可以向前阅读)。

You can compile your web application if you have the Servlet API, no matter where it comes from. After you compiled your web app, you can optionally pack it into a WAR file (WAR=Web ARchive) which is simply a zip file containing your static files, your compiled java classes and configuration files like web.xml etc. And you will be able to run your compiled web application in any Servlet containers (but read forward).

所以回答你的问题#5是:

So answer to your question #5 is:

Servlet API有多个版本,Java EE平台还有更多版本,而不仅仅是Servlet API(例如Enterprise Java Beans)。但可以肯定地说,如果您只使用Servlet API,那么实现该版本Servlet API的所有Servlet容器都将能够运行您的Web应用程序。

There are multiple versions of the Servlet API, and there are more to the Java EE platform than just the Servlet API (e.g. Enterprise Java Beans). But it's safe to say that if you only use the Servlet API, all Servlet containers that implement that version of the Servlet API will be able to run your web application.

不同Web应用程序的配置文件可能会有所不同(在Servlet API范围之外),因此您应该始终检查目标Web应用程序的文档。

The configuration files of the different web applications might differ though (which is outside of the Servlet API scope), so you should always check the documentation of the target web application.

这篇关于了解谁提供了servlet-api.jar,它是web容器还是Java EE下载的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆