Can we call init() method from service() method in servlet ? I got this as an interview question. Why would anyone do this anyway ?
No reason to call init from service, init is meant to be called by the container - to initialise it with configuration (as the name suggests) and to allow it to do any expensive operations it needs to do (setting up connections to database or whatever).
It may make some sense if you wanted to programmatically reconfigure your servlet to call the init from the servlet itself, but I struggle to see this use case.
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