posted 15 years ago
I've struggled with the problem where I wanted to have variables in a web.xml file. I came up with a solution that works but is not so elegant.
Essentially I wrap the real servlet that I want to run in a wrapper servlet that I wrote (SystemPropParametrizedServlet) wherein I can pass System variables via the init-param tag using ${system-var-name} syntax. So basically, when the wrapper servlet gets the init-param's sent to it, it dereferences them to the value set in system properties and passes that to the delegate servlet.
I have included here:
1. web.xml snipped showing it using my servlet with a "delegate" parameter of the class name of the actual servlet and an init-param using the syntax
2. Code for the SystemPropParametrizedServlet delegate
3. A supporting class ParameterSubstituter
And uses: