java2db

How to read the init parameter value in servlet ( init-param )



The init parameters (<init-param>) are specific to a servlet that configured in the deployment descriptor(web.xml)  file.The servlet container provides the ability to store startup and configuration information for a servlet in the form of initialization parameters(init and context).Use getInitParameter() method to read the init parameter value in servlet.

 

Servlet init parameters exist with the (user defined) name and value pair.

Specify the init parameters in the web.xml while configuring the servlet.No other servlet can access it.

 

 

 

Declaration in web.xml :

Always declare the init parameters inside the  <servlet> element.

 <init-param>
     <param-name>parameter1</param-name>
    <param-value>Welcome</param-value>
 </init-param>
create a 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 init parameter value in servlet :

ServletConfig config = getServletConfig();
String init_param1 =  config.getInitParameter(“parameter1“);

or (Call it directly)

String init_param1 =  getInitParameter(“parameter1“);

 

How to read the init parameter value in servlet Get the init parameter names with the below code:

Enumeration<String> params_names = getInitParameterNames();

 

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

How to read the init parameter value in servlet index.jsp

How to read the init parameter value in servlet InitParamExeServlet.java

How to read the init parameter value in servlet web.xml

 

 

Execution result :
get the form data in servlet
On button click, you will get the below output .
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]



^ <