aspose file tools*
The moose likes Websphere and the fly likes environment variable referance in Web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "environment variable referance in Web.xml" Watch "environment variable referance in Web.xml" New topic
Author

environment variable referance in Web.xml

Jayakrishnan R Nair
Greenhorn

Joined: Jan 24, 2008
Posts: 5
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 ]

Theory is when you know something, but it doesn't work.<br />Practice is when something works, but you don't know why.<br />Programmers combine theory and practice: Nothing works and they don't know why.
M Simpson
Greenhorn

Joined: Dec 09, 2009
Posts: 2
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

Joined: Nov 16, 2010
Posts: 1
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
 
subject: environment variable referance in Web.xml