File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "web.xml" Watch "web.xml" New topic



Joined: Oct 01, 2004
Posts: 1
I need ur help.can anyone tell me what does the <init-param></init-param>
tag does in a web.xml file?
Thanks in advance.

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
<init-param>: Each initialization parameter for a servlet is specified using an
<init-param> element. It has child elements <param-name> and
<param-value> which are name and value pair of the parameter. The value of the
initialization parameter can be retrieved in the servlet code using the
getInitParameter() method of the ServletConfig interface. And you can use the method getInitParameterNames to retrieve the names of all parameters. This method will return you an Enumerator object. if there is no parameter defined then an empty Enumerator object would be returned.

Deployment Descriptor:


<servlet-name> TestServlet </servlet-name>
<servlet-class> com.whiz.TestServlet </servlet-class>

it has 1 init-param, name = country and value = Pakistan.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

"RRevathi" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake.

You can change your user name here.

Thanks! and welcome to the JavaRanch!

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 160
to be very simple..

you can imagine them as command line arguments to your Servlet.


the above means , your servlet will get a command line argument named country, whose value is Pakistan. even if you mention in web.xml , its up to you to use it or not in your servlet.

call the getInitParameter("country") of the servlet context , to get the particular parameter value, by passing the parameter name.

Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
I agree. Here's the link:
subject: web.xml
It's not a secret anymore!