Forums Register Login

Regarding Service, SevletConfig and ServletContext

+Pie Number of slices to send: Send
Why shouldn't we override service, getServletContext and getServletConfig methods?
Any reason for this? What will hapen if we override?

Regards,
Sriram
+Pie Number of slices to send: Send
1. service method is common to all HTTP methods like GET, POST, DELETE etc. It gets called whatever the HTTP method of the request is. The default implementation of service method delegates the request to the correct handler for that HTTP method like doGet for GET, doPost for POST etc. If you override the service method, you'll handle all type of HTTP methods with the same code. This might not be correct behavior. Suppose the user sends a DELETE request, then also you'll service that request in a normal form like sending some information etc. But the intention of DELETE requests is to delete the resource.

2. If you want to override the getServletContext and getServletConfig method, you'll also have to override the init(ServletConfig conf) method. The default implementation in the GenericServlet class handles all these details nicely. So normally you only override the init() method without any parameters. This is what the GenericServlet class usually does for you



Implementing this again manually is just a waste of effort...
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1136 times.
Similar Threads
overridding service()
why we should not override service() method in a servlet
Service
About servlet's service() method
Service method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:01:28.