• Request parameters are used by the servlet  to receive data from client to process the request.
  • Some specific data must be supplied to the servlet at the time of initialization of the servlet and this data is specific to the client.But data is not supplied by the client via request parameters
  • Use initialization parameters to supply the data to the servlet at the time of initialization of the servlet. initialization parameters are set in deployment descriptor   (Web.xml).
  • Servlet can access these parameters during the run time
  • Request parameters change form Request to request 
  • Initialization parameters change from servlet to servlet.

Configure  Initialization parameters in Web.xml file:


ServletConfig Methods :

  1. public String getInitParameter(String name): Returns a String containing value of the named parameter, or null if the parameter does not exist.
  2. public Enumeration getInitParameterNames(): Returns names of the servlets initialization parameters as an enumeration of String objects, or an empty enumeration if servelt has no initialization
  3. public String getServletName():Returns the name of the servlet.
  4. public ServletContext getServletContext():Returns an object of ServletContext.


How to get Initialization parameters:

  • To access initialization parameters of a servlet we use servelt config object.
  • ServletConfig is an interface defined by javax.servlet package and this interface is implemented by container.
  • ServletConfig is the object of the class that implements ServletConfig interface and this object is created by servlet conatainer with servlet init() method parameters.
  • For each servlet One ServletConfig object is created by the container.
        ServletConfig sc=getServletConfig();
        String s=sc.getInitParameter("email");
To get all values:

       ServletConfig config=getServletConfig(); 
       Enumeration<String> e=config.getInitParameterNames(); 
       String names=""; 
       out.print("<br>Name: "+str); 
       out.print(" value: "+config.getInitParameter(names)); 

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
Newer Post
Older Post

No comments

Leave a Reply

Select Menu