File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

environment variable referance in Web.xml

 
Jayakrishnan R Nair
Greenhorn
Posts: 5
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have an application. Currently I am initializing my external properties through the below entries in web.xml.

<servlet>
<display-name>ActionServlet</display-name>
<servlet-name>ActionServlet</servlet-name>
<servlet-class>com.jkcool.wbt.bean.common.WebBssServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>/config/ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>conf</param-name>
<param-value>/config/ApplicationConf.properties</param-value>
</init-param>
</servlet>


Right now , I have only one set of property files. But when I go for deployment , I need 3 set of property files - dev,qa and modl for deployment in different regions.

Is it possible to have entries in web.xml like the one below

<servlet>
<display-name>ActionServlet</display-name>
<servlet-name>ActionServlet</servlet-name>
<servlet-class>com.jkcool.wbt.bean.common.WebBssServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>/config/$region_var/ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>conf</param-name>
<param-value>/config/$region_var/ApplicationConf.properties</param-value>
</init-param>
</servlet>


Where $region_var will be an environment variable in Websphere application server. Is it possible ?

Or is there any other way to put external variables in web.xml ?

Thank you
[ January 24, 2008: Message edited by: Jayakrishnan R Nair ]
 
M Simpson
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:



 
Evgeny Kurtser
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same problem and I think I found more simple solution.

Let's say you have system environment variables a.system.variable1=A and a.system.variable2=B

Your web.xml:



Your servlet:


Somethere in your servlet:

I put the later code in my utility class and use it widely in my servlets initialization section.
Hope it will help.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic