GenericServlet
implements ServletConfig
interface which means all the interface functions can be invoked from init()
function of GenericServlet
. Given this context, why does the Servlet container sends ServletConfig
object to init()
method? I would also like to know if the ServletConfig
object that is passed to GenericServlet.init(ServletConfig)
different from GenericServlet object.
Regards, Ravi
GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface.
Interface ServletConfig A servlet configuration object used by a servlet container to pass information to a servlet during initialization.
GenericServlet. The GenericServlet class implements the Servlet interface and, for convenience, the ServletConfig interface.
service() method This method is automatically called by the server whenever a request for a GenericServlet arrives. The service() method accepts two parameters: A ServletRequestObject. A SerlvetResponseObject.
The GenericServlet
implements the ServletConfig
methods by simply delegating to the config object passed to the init method. So it implements ServletConfig
simply for convenience - it then simply delegates. So instead of calling getServletConfig().getInitParameter()
you can call getInitParameter()
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