Technology

What is the Difference Between Generic Servlet and HTTP Servlet? with Proper Definition and Brief Explanation

The main difference between Generic Servlet and HTTP Servlet is that the Generic Servlet is protocol independent and can be used with any protocol like HTTP, SMTP, FTP and CGI whereas HTTP Servlet is protocol dependent and is only used with HTTP protocol.

Servlet is a Java technology that helps develop robust and scalable web applications. It is a platform independent server side component. Furthermore, it is possible to write a Servlet using three methods: by implementing the Servlet interface, by extending the Generic Servlet abstract class, or by extending the Http Servlet abstract class. The Servlet interface is the super interface for both the Generic Servlet and the Http Servlet. It has five abstract methods, and Generic Servlet and Http Servlet inherit these methods.

Key Areas Covered

1. What is Generic Servlet?
     – Definition, Functionality
2. What is Http Servlet?
     – Definition, Functionality
3. What is the difference between Generic Servlet and Http Servlet?
     – Key Differences Comparison

Key terms

Generic ServletHTTP Servlet

What is Generic Servlet

Generic Servlet is the immediate subclass of the Servlet interface. Namely; a method inherited from the Servlet interface called service() is an abstract method on Generic Servlet. The other four methods inherited from the Servlet interface have implementations in Generic Servlet. A programmer extending the Generic Servlet class should override the service() method and write the implementation for it.

Also, Generic Servlet is used with protocols like SMTP, CGI, FTP, HTTP, etc. Therefore, it is protocol independent. In other words, it can be used when the web was not standardized for the HTTP protocol.

What is Http Servelt?

Today most web applications use the HTTP protocol. Http Servlet is designed to support the HTTP protocol. It is also an abstract class. Also, the immediate superclass of HttpServlet is GenericServlet. HttpServlet overrides the service method on GenericServlet. It is possible to override the service (method using doGet() or doPost() with the same parameters of the service method).

Because HttpServlet is the subclass of GenericServlet, it inherits the properties and methods of GenericServlet. Therefore, when the programmer extends the HttpServlet, he can use the functionality of both classes.

Difference between GenericServlet and HttpServlet

Definition

GenericServlet is a class that implements the Servlet, ServletConfig and Serializable interfaces which provide the implementation of all the methods of these interfaces except the service method. HttpServlet is a class that extends the GenericServlet class and implements the Serializable interface that provides HTTP-specific methods. Thus, this indicates the fundamental difference between GenericServlet and HttpServlet.

Dependency Protocol

A fundamental difference between GenericServlet and HttpServlet is that GenericServlet is protocol independent while HttpServlet is protocol dependent.

Service Method

Also, in GenericServlet, the service method is abstract. However, in HttpServlet, the service method is not abstract. So, this is another important difference between GenericServlet and HttpServlet.

Signature

Additionally, the public abstract class GenericServlet extends java.lang.Object and implements Servlet, ServletConfig, and java.io.Serializable. However, the public abstract class HttpServlet is extended, and GenericServlet implements java.io.Serializable.

Associated Subclass

GenericServlet is the immediate subclass of the Servlet interface. HttpServlet, on the other hand, is the immediate subclass of GenericServlet.

Defined Package

The javax.servlet package defines the GenericServlet while the javax.servlet.http package defines the HttpServlet. This is another difference between GenericServlet and HttpServlet.

Extension / Implementation

Additionally, GenericServlet extends the object class and implements the Servlet, ServletConfig, and Serializable interfaces. HttpServlet extends GenericServelt and implements a Serializable interface.

Usability

Another difference between GenericServlet and HttpServlet is that the GenericServlet is not commonly used while the HttpServlet is commonly used.

Conclusion

The main difference between Generic Servlet and HttpServlet is that GenericServlet is a separate protocol that can be used with any protocol like HTTP, SMTP, FTP, CGI, etc.

Reference:

1. “GenericServlet Class in Servlet – Javatpoint.” www.javatpoint.com, available here.
2. “HttpServlet Class in Servlet – Javatpoint.” www.javatpoint.com, available here.

Courtesy image:

1. “Servlet” By Frederik Wahl – Own work (Public Domain) via Commons Wikimedia

See More:
Mohammad Asif Goraya

M A Goraya has qualification of M.phil in Agricultural Sciences. He has almost 15 years of teaching Experience at college and university level. He likes to share his research based knowledge with his students and audience.

Recent Posts

Difference Between Summary and Conclusion with Proper Definition and Brief Explanation

Main Difference - Summary vs Conclusion Summary and conclusion are two terms that are often…

1 year ago

Difference between Moth and Butterfly

Difference between moth and butterfly fall into two categories: anatomical and behavioral. Most moths are…

1 year ago

Difference Between Architect and Engineer

An engineer is a person whose job is to design and build engines, machines, roads,…

3 years ago

Difference between the Internet and the World Wide Web

Internet is the term used to identify the massive interconnection of computer networks around the…

3 years ago

Difference Between CD-R and CD-RW

A CD-R is a type of disc that does not contain any data. It is blank…

3 years ago

Difference between x86 and x64

Computing technologies are constantly evolving, and if we base our predictions on Moore's Law, they…

3 years ago