Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between javax.servlet-api.jar vs servlet-api.jar

Tags:

In my maven repository under groupId javax.servlet i have these two separate artifacts for servlets. I am confused which one should i use to build a simple servlet application? What's the difference between these two artifacts?

like image 480
Ruelos Joel Avatar asked Dec 18 '15 05:12

Ruelos Joel


People also ask

What is the use of servlet API jar?

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.

What is the difference between javax servlet and javax servlet HTTP?

In general javax. servlet package has all the classes/interfaces not directly tied to HTTP, and java. servlet. http package has the classes/interfaces that deals with the http protocol.

What jar files are required for servlets?

You need Servlet-api. jar to compile servlets in eclipse but while deploying servlet container ( like tomcat ) will have it built in.

What is servlet and REST API?

REST is a style of service that uses HTTP operations (GET, PUT, etc.) to read and write the state of resources. Think of resources as "nouns" and "things". Servlet, on the other hand, is a software specification originally provided by Sun Microsystems for connecting HTTP requests to custom Java code.


2 Answers

javax.servlet-api version 3.0.1 has annotation folder which contains different annotation classes where servlet-api version 2.5 or below (i.e version 2.4) does not contain annotation.

Annotation represents the metadata. If you use annotation, deployment descriptor i.e. web.xml is not required. For example if you use annotation like @WebServlet("/hello") in your servlet file then you don't need to mention servlet mapping in web.xml file.

Some of useful Annotations are:

@HandlesTypes @HttpConstraint  @HttpMethodConstraint @MultipartConfig @ServletSecurity @WebFilter @WebInitParam @WebListener @WebServlet 
like image 95
Luffy Avatar answered Sep 28 '22 22:09

Luffy


You need to add

<dependency>         <groupId>javax.servlet</groupId>         <artifactId>javax.servlet-api</artifactId>         <version>3.1.0</version>         <scope>provided</scope> </dependency> 

to your project. The version you need may differ - it depends on your servlet container, e.g. Tomcat.

<scope>provided</scope> because you don't need it in runtime, it's already in your servlet container.

like image 42
dds Avatar answered Sep 28 '22 20:09

dds