Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web.xml

 
RRevathi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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!
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic