Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » Java » Difference between GenericServlet and HttpServlet

  • Hima Das Biography | भारतीय धाविका हिमा दास का जीवन परिचय
    Hima Das Biography | भारतीय धाविका हिमा दास का जीवन परिचय Biography
  • International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं?
    International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं? General Knowledge
  • Kishore Kumar Biography in Hindi | किशोर कुमार की जीवनी
    Kishore Kumar Biography in Hindi | किशोर कुमार की जीवनी Biography
  • Chhath Puja Story
    Chhath Puja History : क्यों मनाते हैं छठ महापर्व Festival
  • Ohms law Definition, Formula, Statement
    Ohms law Definition, Formula, Statement | ओम का नियम Science
  • Lanka Kand Summary in Hindi | Ram Vs Ravana | लंका काण्ड
    Lanka Kand Summary in Hindi | Ram Vs Ravana | लंका काण्ड Spiritual
  • Indian Navy Day
    Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है? General Knowledge
  • Real life Inspirational Stories in Hindi | Success story in Hindi
    Real life Inspirational Stories in Hindi | Success story in Hindi Biography

Difference between GenericServlet and HttpServlet

Posted on August 13, 2021June 18, 2022 By GeekCer Education No Comments on Difference between GenericServlet and HttpServlet
Difference between GenericServlet and HttpServlet

The GenericServlet Vs HttpServlet section will help you to know the basic and most important difference between them. But Interviewers usually ask these types of questions in interviews for Java Developers.

By using both GenericServlet and HttpServlet we create servlets but the main difference between GenericServlet and HttpServlet is that GenericServlet is protocol-independent while HttpServlet is protocol-dependent.

Table of Contents

  • GenericServlet Vs HttpServlet
  • Example of GenericServlet with example
  • Example of HttpServlet with example

GenericServlet Vs HttpServlet

The primary difference between HttpServlet and GenericServlet is that HttpServlet is protocol dependent and used only with HTTP protocol whereas GenericServlet is protocol independent which can be used with any protocol.

GenericServlet belongs to javax.servlet package but HttpServlet belongs to javax.servlet.http package.

HttpServlet is the most commonly used servlet by Java programmers whereas Servlet is not commonly used.

GenericServlet allows all types of protocols and has only one abstract method which is service() method and other four methods are concrete method whereas HttpServlet is a class which is specific and allows only http protocol and other protocol like FTP doesn’t allow SMTP.

#GenericServletHttpServlet
1.GenericServlet defines a generic and protocol-independent servlet.But HttpServlet defines a HTTP protocol specific servlet.
2.In GenericServlet, the service() method is abstract.But service() method in HttpServlet is non-abstract.
3.GenericServlet extends Object class and implements Servlet, ServletConfig, and Serializable interfaces.But HttpServlet extends GenericServlet and implements a Serializable interface.
4.GenericServlet supports only service() method which does not contain doGet() and doPost() methods.HttpServlet also supports doGet(), doPost(), doHead(), doPut(), doOptions(), doDelete(), doTrace() methods.
5.GenericServlet can process multiple clients request from a single form hence programmer doesn’t prefer this servlet.HttpServlet can process multiple clients requesting from multiple HTML forms hence programmer prefer this servlet.
6.GenericServlet is Stateless and is not commonly used servlet.But HttpServlet is Stateful and it is most popular servlet because it is commonly used by the developer.

Example of GenericServlet with example

Read example program of GenericServlet class in Servlet

Example of HttpServlet with example

Read example program of HttpServlet class in Servlet

After learning GenericServlet Vs HttpServlet, finally you are able to decide which servlet you should prefer for writing servlet program.

Recommended Articles

  • HashCode importance in HashMap Internal workings
  • DBMS characteristics in Detail
  • How to create a servlet | Steps
  • Create war file in java using command prompt
  • Use of lambda expression in java
  • map in java 8 stream

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

Differences, Java

Post navigation

Previous Post: Steps of Database Connectivity in Java
Next Post: Difference between Internet and Intranet

More Related Articles

Java Learning Tutorial Java Tutorial for Advanced Learning, Buzzwords, Parts of Java Java
Structured Vs Unstructured Data in Hindi | Key Difference Structured Vs Unstructured Data in Hindi | Key Difference Differences
Difference between Structure and Class in C++ in tabular form Difference between Structure and Class in C++ in tabular form Differences
Java LinkedList Java LinkedList Java
Java 11 new Features (With example Programs) Java 11 new Features (With example Programs) Important
Data Types in Java Data Types in Java Java

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved