File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets" Watch "servlets" New topic


kurian chacko

Joined: Sep 28, 2008
Posts: 5
Difference between Generic Servlet & Servlet?

A servlet is extended by HttpServlet -----> Generic Servlet ---------->Then our Servlet.
HttpServlet is needed b'coz we need to create the request & response objects of the HttpServletResponse & HttpServletRequest interfaces for which the implementation is given by the webcontainer.
They say that Generic Servlet is equivalent to Servlet.

Ajay Vikas
Ranch Hand

Joined: Nov 08, 2006
Posts: 66
I feel, Generic servlet is kept as plain Servlet becaouse, GenericServlet is for servlets that might not use HTTP, like for instance FTP servlets. Of course, there's no such thing as FTP servlets, but they may try to plan for future growth when they designed the spec. Maybe some day there will be another subclass, but for now, always use HttpServlet.

So currently we use HTTPServlet for our webservers as it supports only HTTP. In future we may come across servlets with other protocols such as FTP, LDAP, ... etc.
Hope So,

Ajay Vikas.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
A servlet is extended by HttpServlet -----> Generic Servlet ---------->Then our Servlet.

I think you got that the wrong way around. Your servlet extends HttpServlet, which extends GenericServlet. Strictly speaking, that all is required of your servlet is that it implements the Servlet interface. But practically, HttpServlet does some useful things that just about all servlets will need to do, so it would be silly not to extend that insteaad.

Support for FTP in servlets is highly unlikely, as are just about all other protocols. See for details.

As a hint, next time please UseAMeaningfulSubjectLine. "servlets" is way too generic to provide a clue what the question is about. And welcome to JavaRanch!
[ October 03, 2008: Message edited by: Ulf Dittmer ]
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237


YourServlet extends HttpServlet
HttpServletExtends GenericServlet
GenericServlet extends Servlet
so yourServlet dont need to implement any mehtods..all the parent interface methods were implemented..

yourServlet extends HttpServlet to get the benefit of being a web application..

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
GenericServlet extends Servlet

I think you meant to say implements instead of extends.

so your servlet doesn't need to implement any methods

Of course, if it doesn't override any methods it won't be able to do much useful work :-)
[ October 03, 2008: Message edited by: Ulf Dittmer ]
I agree. Here's the link:
subject: servlets
It's not a secret anymore!