aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HF-pg98 : HttpServlet is an abstract class ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HF-pg98 : HttpServlet is an abstract class ?" Watch "HF-pg98 : HttpServlet is an abstract class ?" New topic
Author

HF-pg98 : HttpServlet is an abstract class ?

Frederico Werly
Greenhorn

Joined: Sep 14, 2004
Posts: 18
Im confused,

If "HttpServlet" is an abstract class, why not my concrect sub-class "MyServlet" dont implement many abstract methods from "HttpServlet" ?

"MyServlet" just override doPost and create other method called myBizMethod();

I think that if im inherited an Abstract class, i must to implement many abstract methods from the super abstract class ... im right ?

Thanks


SCJP 1.4<br />--------<br />Sorry for my english, im half in english, i speak portuguease ;-)
Benny Brown
Greenhorn

Joined: Sep 25, 2004
Posts: 7
Hello Frederico.

I guess the answer to this question is similar to the answer regarding HttpServletResponse and -Request interfaces on top of page 107 HF S&J. The Container vendor has already extended/implemented all servlet abstract classes and interfaces and when we use instances of these classes in our code, we are really using objects of these "vendor"-classes behind the scene.

Hope this helps

Regards
Benny
Frederico Werly
Greenhorn

Joined: Sep 14, 2004
Posts: 18
Ok, in the response and request interfaces i understand, there are objects that was implemented by container and im using the reference to this objects.

But , in HttpServlet abstract class , i inherited direct from this class .. so i need to implement many abstract methods .

Or the container changes my code to put another class that implemts HttpServlet ? if its true ... so i understand , because "MyServlet" is inherited a class that implements the Abstract class HttpServlet .

Thanks for answer.
Colin Fletcher
Ranch Hand

Joined: Sep 10, 2004
Posts: 200
Frederico, I partially understand what you problem is, I think.

For my 'Movie' servlet, I extended the HttpServlet class.. From the class I can call a custom method do perform some activity.

I don't implement any other methods in the Movie class....



SCJP 1.4 SCWCD 1.4
Frederico Werly
Greenhorn

Joined: Sep 14, 2004
Posts: 18
Ok Colin .. thanks for reply .

but .. i know that this code above run without problem , i just want to understand how ou who implements the abstract methods from HttpServlets ?

If HttpServlet is an Abstract class ...so there are many abstract methods in this class right ? so when i inherited one class from HttpServlet i dont implements these methods ... who implements ? do the container changes in my code to refer to another class taht implements HttpServlet ?

i know that it run .. i want to understand how ...

Thanks a lot for replys
vishwa venkat
Ranch Hand

Joined: Nov 22, 2003
Posts: 185
HttpServlet class doesn't contain any abstract methods.so u don't have to implement all the methods in that class when u derive from HttpServlet.
If u still have problem in unserstanding, please refer
http://java.sun.com/docs/books/tutorial/java/javaOO/abstract.html
siva raju
Ranch Hand

Joined: Oct 10, 2003
Posts: 37
Hi Frederico,

Even though HttpServlet is an abstract class, it does not have any abstract methods. Hence, you need not implement any.
But the docs say that you must override atleast one method. The container implementation of these methods like doPost, doGet etc will be to show some kind of an error.
If you do not override, say doGet() and issue an url for this servlet, you might get something like
HTTP method GET is not supported by this URL (on Tomcat 5.0)

Hope this clarifies your doubt.

Cheers,
Siva.
siva raju
Ranch Hand

Joined: Oct 10, 2003
Posts: 37
Oops, didn't see visu's reply. Else, i wouldn't have reinvented the wheel.
Frederico Werly
Greenhorn

Joined: Sep 14, 2004
Posts: 18
Ok !! i did understand ..

My doubt was that the HttpServlet dont has any abstract methods ... so i dont need to implement any .

Only the class is abstract... there are no abstract methods ..

Thanks a lot friends
 
 
subject: HF-pg98 : HttpServlet is an abstract class ?