I'm creating a servlet that needs to load configuration information. Part of the configuration information I need is a list of Strings (specifically, a list of hostnames and/or URLs).
I was hoping to store this information in my servlet's web.xml file (so I don't have to write my own parser) as either a context-param or init-param; essentially multiple param-value's for a single param-name.
Example of what I would like:
<context-param> <param-name>validHosts</param-name> <param-value>example1.com</param-value> <param-value>example2.com</param-value> <param-value>example3.com</param-value> </context-param>
My initial research seems to indicate this is not possible--that there can only be a single param-value for any param-name (within either context-param or init-param).
I know I could just use a delimited list within a single param-value, but is that really my only option if I still want to use web.xml? Should I just stop whining and write my own config file parser?
The optional context-param element declares a Web Application's servlet context initialization parameters. You set each context-param within a single context-param element, using <param-name> and <param-value> elements. You can access these parameters in your code using the javax.
The init-param element within a filter or servlet definition element contains initialization parameters for that filter or servlet instance. These are distinct from context parameters, discussed in Section 4.7. Each init-param contains a param-name element and a param-value element.
You can specify initial parameter values for servlets in web modules during or after installation of an application onto a WebSphere® Application Server deployment target. The <param-value> values specified in <init-param> statements in the web. xml file of web modules are used by default.
Servlet init parameters are for a single servlet only. Nothing outside that servlet can access that. It is declared inside the <servlet> tag of Deployment Descriptor, on the other hand context init parameter is for the entire web application. Any servlet or JSP in that web application can access context init parameter.
Servlet spec says that you can have only one value for any context parameter. So, you are left with going with delimited list only.
<context-param> <param-name>validHosts</param-name> <param-value>example1.com,example2.com,.....</param-value> </context-param>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With