The Artima Developer Community
Sponsored Link

Java Buzz Forum
Difference between GenericServlet vs HttpServlet in Servlet JSP - J2EE question

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Difference between GenericServlet vs HttpServlet in Servlet JSP - J2EE question Posted: Dec 16, 2012 5:37 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Difference between GenericServlet vs HttpServlet in Servlet JSP - J2EE question
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Difference between GenericServlet and HttpServlet is one of the classic Servlet Interview Question, asked on many Servlet and JSP Interviews on 2 to 4 years experience developers. Since both GenericServlet and HttpServlet forms basis of Servlets its important to know What are they and What is main difference between them. From common sense and there names, its obvious that GenericServlet is a generic and protocol independent implementation of Servlet interface while HttpServlet implements HTTP protocol specifics. If you are working in Java web application or J2EE projects, you are most likely to deal with HttpServlet all time as HTTP is main communication protocol of web. In this Servlet JSP article we will outline some important difference between HttpServlet and GenericServlet which is worth knowing and remembering.

GenericServlet vs HttpServlet

Difference between GenericServlet and HTTPServlet in JSP
Here is my list of difference between HttpServlet and GenericServlet in Java Servlet API :

1) GenericServlet provides abstract service(ServletRequest, ServletResponse) method to implement which gets called by container whenever it receives request for processing, On the other hand HttpServlet overrides service method and provides callback on doGet(HttpServletRequest request, HttpServletResponse) and doPost(HttpServletRequest request, HttpServletResponse response) whenever it receives HTTP request from GET or POST method. It also provides several other method based upon various HTTP methods of sending request e.g. doPut() or doDelete() to handle HTTP PUT and HTTP DELETE request.

2) Another difference between GenericServlet and HttpServlet is that later is a subclass of GenericServlet and inherit properties of GenericServlet.

3) Generic servlet provides a rather easier way to extend Servlet, its enough to override service method to implement GenericServlet. Apart from extending Servlet interface, it also implements ServletConfig interface and provides way to accept initialization parameter passed to Servlet from web.xml e.g. by using getInitParamter().

That's all on difference between GenericServlet and HttpServlet in Servlet API. Its very rare you are going to use GenericServlet but its good to know basics as its mostly asked in various Servlet interviews as well. HttpServlet is primary Servlet class which is used in Java web application from handling client request.

Other Servlet and JSP questions you like to prepare

Read: Difference between GenericServlet vs HttpServlet in Servlet JSP - J2EE question

Topic: Dynamic hot-swap environment inside Java with atomic updates Previous Topic   Next Topic Topic: Composing Java annotations

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use