Forums Register Login

HF-pg98 : HttpServlet is an abstract class ?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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....

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Oops, didn't see visu's reply. Else, i wouldn't have reinvented the wheel.
+Pie Number of slices to send: Send
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
I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 989 times.
Similar Threads
Abstract classes
HttpServlet absract class
HttpServlet
Is HttpServlet an abstract class or interface?
Basic Servlet Doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:06:50.