I understand that the GenericServlet is protocol independent and an abstract class. So my questions is when someone would chose to use GenericServlet? Do you know of any specific example in mind that uses GenericServlet?
I have always correlated servlets with HTTP protocol and its responses and requests. I can not think of how a servlet can be useful in a protocol other than HTTP. It doesn't mean that it can not be. The option of being used in other protocol might have not been utilized in the past and there is no need for it anymore. Or it might be me that I don't have enough knowledge of it.
The short answer to your question is "Never. Practically speaking."
The long answer is that GenericServlet
is an abstract (can't be instantiated) protocol-independent servlet, which is an endpoint accessible over a network like the web. GenericServlet
provides some basic lifecycle management, but you have to extend it to make anything useful.
HttpServlet
is an implementation of GenericServlet
that handles many of the low-level details of the HTTP protocol like headers, chunking, cookies, and so on. As a practical matter, this is the only implementation anyone cares about.
I suppose it is theoretically possible one could extend GenericServlet
to implement a different protocol like FTP or SMTP, but why bother?
Hope that helps.
GenericServlet doesn't implements all 10 HTTP protocol request (get post put delete head trace connect options etc.). so If you extend GenericServlet then all the request gonna invoke service() method. as solution to this HttpServlet implements them so you can perform difference action according to the Request Received.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With