getContextPath () , and here is a method for using it with getInitParameter ()
As an example, if you had two contexts: " / dev " and " / prod " - as indentical - and you created your network. xml with entries like:
<context-param> <param-name>database_ip_prod</param-name> <param-value>192.168.1.10</param-value> </context-param> <context-param> <param-name>database_ip_dev</param-name> <param-value>127.0.0.1</param-value> </context-param>
And using this method:
public String getContextInitParam( javax.servlet.ServletContext context, String key) { key += context.getContextPath().replace("/","_"); return context.getInitParameter(key); }
A call like this from jsp or servlet:
getContextInitParam (request.getServletContext (), "database_ip" );
returns 192.168.1.10 in the / prod context and 127.0.0.1 in the / dev context.
source share