On Thu, 31 Oct 2002, Chris Brown wrote:
> Date: Thu, 31 Oct 2002 09:28:18 +0100
> From: Chris Brown <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: tomcat-user <[EMAIL PROTECTED]>
> Subject: Using JNDI URLs for embedded XML DTDs, to avoid hard-coding
>
>
> Hello all,
>
> Any ideas as to how I can make an XML DTD/Schema available via a JNDI URL
> within Tomcat?
The simplest way to do this is to use a JNDI "environment entry" that
defines the URL (as a String) and sticks it in the JNDI naming context for
you. The actual value to be used is configured in server.xml (or
your context config file under 4.1).
Nested in your <Context> element, you'd set up something like this:
<Context path="..." ...>
...
<Environment name="url" type="java.lang.String"
value="http://..."/>
...
</Context>
and access it from your application like this:
InitialContext ic = new InitialContext();
String url = (String) ic.lookup("java:comp/env/url");
In this way, you can deploy the same WAR unchanged, in different
environments, by tweaking things in the server.xml file.
A similar alternative would be to use a context initialization parameter,
which Tomcat lets you configure in server.xml with a <Parameter> element,
and retrieve it with:
ServletContext sc = ... context instance passed to your class ...;
String url = sc.getInitParameter("url");
In either case, the configured value will be available in the
contextInitialized() method of a ServletContextListener, or at any other
time during the execution of your application.
Craig
--
To unsubscribe, e-mail: <mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>