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

  • Farmers Day
    National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती General Knowledge
  • Lanka Kand Summary in Hindi | Ram Vs Ravana | लंका काण्ड
    Lanka Kand Summary in Hindi | Ram Vs Ravana | लंका काण्ड Spiritual
  • Rabindranath Tagore Biography in Hindi, Poems, Birthday
    Rabindranath Tagore Biography in Hindi, Title of Gurudev Biography
  • Kishkindha Kand in Hindi | Ram meets Hanuman | किष्किंधा कांड
    Kishkindha Kand in Hindi | Ram meets Hanuman | किष्किंधा कांड Spiritual
  • Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा
    Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा Festival
  • Chhath Puja Story
    Chhath Puja History : क्यों मनाते हैं छठ महापर्व Festival
  • Ramayana Uttar Kand Luv Kush| रामायण उत्तर कांड इन हिंदी
    Ramayana Uttar Kand Luv Kush | रामायण उत्तर कांड इन हिंदी Spiritual
  • States of Matter : Physical Properties of Matter (Solid, Liquid, Gas)
    States of Matter | Physical Properties of Matter (Solid, Liquid, Gas) Science

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

Steps of Database Connectivity in Java Steps of Database Connectivity in Java Java
Object Oriented Programming Object Oriented Programming Java
Jenkins java | Installing Jenkins on Windows Jenkins java | Installing Jenkins on Windows Important
Concurrent collections in Java, details, advantages, examples Concurrent collections in Java, details, advantages, examples Java
Difference between JPanel and JFrame Difference between JPanel and JFrame Differences
Java Vector Vector in Java Collection, Constructors, Example Programs 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 | द्रौपदी मुर्मू की जीवनी
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, 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