Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

Getting Init Parameter Names

In this example we are going to retreive the init paramater values which we have given in the web.xml file.



Getting Init Parameter Names


In this example we are going to retreive the init paramater values which we have given in the web.xml file.

Whenever the container makes a servlet it always reads it deployment descriptor file i.e. web.xml. Container creates name/value pairs for the ServletConfig object.  Once the parameters are in ServletConfig they will never be read again by the Container.

The main job of the ServletConfig object is to give the init parameters.

To retrieve the init parameters in the program firstly we have made one class named GettingInitParameterNames. The container calls the servlet's service() method then depending on the type of request, the service method calls either the doGet() or the doPost(). By default it will be doGet() method. Now inside the doGet() method use getWriter() method of the response object which will return a object of the PrintWriter class which helps us to print the content on the browser.

To retrieve all the values of the init parameter use method getInitParameterNames() which will return the Enumeration of the init parameters.

The code of the program is given below: 

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class InitServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, 
   HttpServletResponse response
  throws ServletException, IOException {
  PrintWriter pw = response.getWriter();
  pw.print("Init Parameters are : ");
  Enumeration enumeration = getServletConfig().getInitParameterNames();
  pw.print(enumeration.nextElement() " ");
  pw.println("\nThe email address is " 
  pw.println("The address is " 
  pw.println("The phone no is " 

web.xml file of this program:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"


 The output of the program is given below:

Download this example


Share on Google+Share on Google+

Getting Init Parameter Names

Posted on: July 14, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Getting Init Parameter Names   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
February 8, 2012
about servletconfig

Thanks for great work helps a lot
August 17, 2012
Thanking You

Good Tutorial......Keep it up!!!!!
March 27, 2013
How to set data into jsp page from database

I want know about set data into jsp from Mysql database give me a example... thank you
kamal chetry
May 23, 2014
drodown menu in jsp

i am new in jsp and i want to populate a dropdown menu in jsp page using jsp and servlet. and i am using net bean IDE to developed the program.comment please