java2db

How to read the context parameters in servlet ( context-parm )



The context parameters (<context-param>) are not specific to a servlet, multiple servlets in the web application can access it.Use servletcontext.getInitParameter() method to read the context parameters in servlet.

The servlet container provides the ability to store startup and configuration information for a servlet in the form of initialization parameters(init and context).

 

Context parameters contains (user defined) name and value pair.

Declare the context parameters in the web.xml under <web-app> element. So that all the servlets under <web-app> can access it .

 

Context parameter declaration in web.xml :

Always declare the context parameters inside the <web-app> root element.

<web-app>
<context-param>
<param-name>parameter1</param-name>
<param-value>Welcome</param-value>
</context-param>
</web-app>
How to read the context parameters in servletWe can configure multiple <param-values> to a <param-name>.But we can read only the bottom value.

 

How to read the init parameter value in servlet Code to read the context parameters in servlet :

———————————————————————————————————————————————————————-

How to read the context parameters in servlet Read the context parameter values :

ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();
String context_param1 = context.getInitParameter(“parameter1“);

 

or (Call it directly)

 

ServletContext context = getServletContext();
String context_param1 = context .getInitParameter(“parameter1“);

 ———————————————————————————————————————————————————————

How to read the context parameters in servlet Read context parameter names :

ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();
Enumeration<String> param_names = context.getInitParameterNames();

 

or (Call it directly)

 

ServletContext context = getServletContext();
Enumeration<String> param_names = context.getInitParameterNames();

 ——————————————————————————————————————————————————————

 

How to read the init parameter value in servlet Example to read the context parameters in servlet :

How to read the context parameters in servlet index.jsp

How to read the context parameters in servlet ContextParamExeServlet .java

How to read the context parameters in servlet web.xml

 

Execution Result :
get the form data in servlet
get the form data in servlet




Related Posts :
Kill or invalidate session using session id ( concurrent login )
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Servlet Cookies ( Servlets session tracking with cookie )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
   [will not be published]



^ <