• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to initialize a value in web.xml from a JNDI variable?  RSS feed

 
Veera Sundar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In my Java web application, the NTLM domain controller name is specified in web.xml like this:



In the above XML, we've hard-coded the domain controller name (DCNAME) in the param-value tag.

Now, is it possible to read this 'DCNAME' from a JNDI variable, instead of hard-coding it in web.xml file?

thanks in advance
 
Anand Kumar Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat 5 provides a JNDI InitialContext implementation instance for each web application running under it.

The J2EE standard provides a standard set of elements in the /WEB-INF/web.xml file to reference resources; resources referenced in these elements must be defined in an application-server-specific configuration.

For Tomcat 5, these entries in per-web-application InitialContext are configured in the <Context> elements that can be specified in either $CATALINA_HOME/conf/server.xml or, preferably, the per-web-application context XML file (either META-INF/context.xml).

You can to define an environment resource like this:

<Environment name="myEnvName" value="whatever"
type="java.lang.String" override="false"/>

and then read it from java code:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
String myEnvName = (String) envCtx .lookup("myEnvName");

For more info go to http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

 
Vivek Kr Singh
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck with JCIFS. We had a tough time with it.

Using context.xml per application is always preferred against setting values in tomcat config. However tomcat will make a copy of context.xml which will be cached in server "work" directory as <application-name>.xml. If the changes that you do in context.xml are not reflected immediately, consider deleting the cached file.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!