aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "web.xml" Watch "web.xml" New topic
Author

web.xml

RRevathi
Greenhorn

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.


wbcool
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:

i.e.

<servlet>
<servlet-name> TestServlet </servlet-name>
<servlet-class> com.whiz.TestServlet </servlet-class>
<init-param>
<param-name>country</param-name>
<param-value>Pakistan</param-value>
</init-param>
</servlet>

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

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!


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

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

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

<init-param>
<param-name>country</param-name>
<param-value>Pakistan</param-value>
</init-param>


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: http://aspose.com/file-tools
 
subject: web.xml
 
Similar Threads
Internationalization of Struts program
ServletException in Struts
web.xml details ?
Struts - Error - "Cannot find ActionMappings or ActionFormBeans collection"
Unable to get init parameters in servlet