How to store string values in context.xml

You can use an Environmenttag:

<Context>
    <Environment name="myConnectionURL" value="amqp:5272//blah.example.com&param1=4" type="java.lang.String"/>
</Context>

And you can read it almost as you specified in the question:

InitialContext initialContext = new InitialContext();
Context environmentContext = (Context) initialContext.lookup("java:/comp/env");
String connectionURL = (String) environmentContext.lookup("myConnectionURL");

This is much the same as using a Parameter tag, but without the need for a ServletContext.


You can configure named values that will be made visible to the web application as servlet context initialization parameters by nesting elements inside this element. For example, you can create an initialization parameter like this:

 <Context>
      ...
     <Parameter name="companyName" value="My Company, Incorporated"
          override="false"/>
       ...
 </Context>

   This is equivalent to the inclusion of the following element in the web application deployment descriptor (/WEB-INF/web.xml):



 <context-param>
       <param-name>companyName</param-name>
       <param-value>My Company, Incorporated</param-value>
 </context-param>

Your java code looks like this

 ServletContext sc = getServletContext();  

 String companyName = sc.getInitParameter("companyName");  

Please see the reference http://tomcat.apache.org/tomcat-7.0-doc/config/context.html