Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

environment variable referance in Web.xml

 
Greenhorn
Posts: 7
  • Likes 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 ]
 
Greenhorn
Posts: 2
  • 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:



 
Greenhorn
Posts: 1
  • 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.
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic