SERVLET CONFIG
A servlet specific configuration object created by a servlet container(W.C) to pass information to a servlet during initialization.
Defined in
Servlet Config's empty instance is created by the Web container(WC) after instantiation of servlet instance and before call to init() using
dependency injection
.To pass servlet specific initialization parameters, we need this servlet config instance, as we cannot pass servlet specific initialization parameter through default constructor() there is no parametrized servlet constructor. (i.e the init-param is accessible to one servlet only or you can say that the init-param data is private for a particular servlet.)
Where to add these servlet specific initialization parameters?
Can be added either in
web.xml
or@WebServlet
annotation.But preferable is
web.xml
so as to keep these configuration external to java code, so that changes to java source code and hassles of recompilation can be avoided.XML Tags
Annotations
To access servlet specific initialization parameters from a servlet, override the
init()
method.To get Servlet Config object of the servlet class use,
To get the init parameters from ServletConfig
Last updated