• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpServlet absract class

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
]
 
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic