File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: environment variable referance in Web.xml
 
Similar Threads
my servlet can't initialize: null
Unable to read TLD "META-INF/jsf_core.tld from jsf-impl-2.0.jar when "Integrating JSF with Struts
servlet.log not working in struts/tomcat environment
HttpSessionListener is not getting invoked
Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6)