File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HttpServlet absract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServlet absract class " Watch "HttpServlet absract class " New topic
Author

HttpServlet absract class

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
I know that Http Servlet extends the generic Servlet and impliments the HTTP protocol. The generic servlet is protocol independent.
Now My quesion is does the HTTP servlet impliment any previous abtract methods from the Generic Servlet or does it simply extend the Generic servlet by adding new methods.
From http://download.oracle.com/javaee/1.2.1/api/javax/servlet/http/HttpServlet.html I think it only adds new unabstract methods.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If you compare the javadocs of GenericServlet and HttpServlet, do you see any methods that are abstract in the former, but not abstract in the latter?

As an aside, you may want to switch to a newer version of the JEE javadocs: http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServlet.html.
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
From the document it says that the GenricServlet only has one abstract method which is the service method and HttpServlet abstract class does not have any abstract methods. So let me know if i am correct The HttpServlet only impliments the Service method of the Generic Servlet other than that it adds its on new methods.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
A subclass can add new methods (like the various doXYZ methods), implement abstract method of the superclass (like service), and it can override existing methods. For the latter to happen, there would need to be methods with the same names, parameters, and return types in both classes; do you see any such methods?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12783
    
    5
Building HttpServlet on top of GenericServlet is pretty typical Java practice.

The HttpServlet service method provides specific recognition of HTTP methods, dispatching to doGet or doPost etc for the HTTP request as required. Naturally the only default behavior for any of these methods is the "not supported" error. Thats why HttpServlet is abstract and you must implement your own extension of the actions you want your application to support. There is utterly no reason to override the HttpServlet service method.

Bill


Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
William Brogden wrote:Building HttpServlet on top of GenericServlet is pretty typical Java practice.

The HttpServlet service method provides specific recognition of HTTP methods, dispatching to doGet or doPost etc for the HTTP request as required. Naturally the only default behavior for any of these methods is the "not supported" error. Thats why HttpServlet is abstract and you must implement your own extension of the actions you want your application to support. There is utterly no reason to override the HttpServlet service method.

Bill



Interesting point. Overriding the HttpServlet method is out of the question , I was merely establishing the fact that HttpServlet actually implements the service abstract method of the GenericServlet class. Furthermore I am having a bit difficulty understanding your reason for why the HttpServlet class was made abstract. I hope you can shed some light on that..
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
William Brogden wrote:There is utterly no reason to override the HttpServlet service method.

If you'd said "for 99.999% of all developers there's no reason", I'd have agreed. But anyone wanting to implement HTTP extensions will have to override the service method in order for the additional HTTP methods to be recognized. WebDAV is probably the best-known HTTP extension.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12783
    
    5
I have always felt that designers make classes abstract as guidance to developers. You see an abstract class and you know that you will have to extend it in order to get the behavior you need.

Bill
]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServlet absract class