How do you pass parameters to servlets with web.xml?

Alessandro A. Garbagnati

If you want something general (for the entire context, you should use something like this:

...
<context-param>
  <param-name> NAME </param-name>
  <param-value> VALUE </param-value>
</context-param>
...

[These are accessible from Java by calling ...? -A]

If you need to set parameters for a single servlet, then use the <init-param> tag inside the servlet tag:

<servlet>
  <servlet-name>...</servlet-name>
  <servlet-class>...</servlet-class>
  <init-param>
    <param-name> NAME </param-name>
    <param-value> VALUE </param-value>
  </init-param>
</servlet>

[These are accessible from Java by calling getInitParameter("NAME") -A]

See also How do I set init parameters in the servlet engine?

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact