How do you pass parameters to servlets with web.xml?
Created May 4, 2012
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>
...
...
<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:
[These are accessible from Java by calling
See also How do I set init parameters in the servlet engine?
<servlet>
<servlet-name>...</servlet-name>
<servlet-class>...</servlet-class>
<init-param>
<param-name> NAME </param-name>
<param-value> VALUE </param-value>
</init-param>
</servlet>
getInitParameter("NAME")
-A]