Understanding who provides servlet-api.jar, is it web-container or part of Java EE download

What is it?

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.

Where can you get it?

It is provided at the link below:

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

Where it is contained/bundled

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

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.

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/

Portability

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

So answer to your question #5 is:

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.

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.


What is servlet-api.jar?

It is a jar that provides the necessary interfaces/classes to write Servlets.

Who provides this jar?

Any servlet container such as Jetty or Tomcat and any Java EE compliant application server like JBoss/Wildfly, GlassFish, IBM WebSphere, Oracle WebLogic, etc.

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.

Yes for the servlet api because it is a set of interfaces, which enables programming to interfaces rather than class implementations so we avoid programming to a specific application server. The name of the jar containing the implementation must not have part of this name in common.

When we download Java EE , is this jar part of download? OR do we get this file as part of web container?

Java EE download available in Oracle is just GlassFish. This is covered previously.

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?

As long as you don't use a Tomcat specific class, library or feature, then yes, there would be no problem. Otherwise, no.