servletcontextlistener - Get servlet init params in servlet context listener -
<listener> <listener-class>config</listener-class> </listener> <servlet> <servlet-name>processreg</servlet-name> <servlet-class>processreg</servlet-class> <init-param> <param-name>text</param-name> <param-value>helloworld1</param-value> </init-param>
public class config implements servletcontextlistener { @override public void contextinitialized(servletcontextevent event) { servletcontext servletcontext = event.getservletcontext(); string text1 = servletcontext.getinitparameter("text");
in method contextinitialized(servletcontextevent event)
, if there 2 servlets , example , let's name of second servlet servlet2
, let's has has init - param
called text
value helloworld2
.
how listener
know take processreg
servlet ?
how param
servlet2
??
you need distinguish between servlet initialization parameters , context initialization parameters.
context initialization parameters are:
- context-wide;
- declared in
<context-param>
elements directly under<web-app>
root; - typically accessed using
servletcontext.getinitparameter()
method, e.g. inside listener'scontextinitialized()
method.
servlet initialization parameters are:
- servlet-specific;
- declared in
<init-param>
elements inside<servlet>
element; - typically accessed using
servletconfig.getinitparameter()
method, e.g. inside servlet'sinit()
method.
Comments
Post a Comment