I have an application that needs to read the <env-entry> information. At
present I can use the following code to read the initialization parameters:
ServletConfig srvCfg = getServletConfig();
String sSomeData = servCfg.getInitParameter("SomeData");
But I'd like to be able to read the data from the <env-entry>. Obviously
this is a servlet and it's running under Tomcat 5.0.
Thanks,
Ed
> But I'd like to be able to read the data from the <env-entry>.
> Obviously this is a servlet and it's running under Tomcat 5.0.
Context ctx = new InitialContext( );
String envVar = (String) ctx.lookup("java:comp/env/envVar");
See
<http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html>
Bye.

Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
Ed Faulk - 20 Sep 2004 04:30 GMT
> > But I'd like to be able to read the data from the <env-entry>.
> > Obviously this is a servlet and it's running under Tomcat 5.0.
[quoted text clipped - 3 lines]
>
> See
<http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html>
Yes, I tried that. Here's a sample piece of code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.naming.*;
public class EnvTest extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String sName = "java:comp/env";
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup(sName);
out.println("Got the environment context...");
sName = "MailServer";
String envVar = (String) envCtx.lookup(sName);
out.println("envVar: " + envVar);
}
catch (NamingException e) {
out.println("NamingException, problem looking up: \"" + sName +
"\"\nproblem is: " + e);
}
}
}
which results in the following:
NamingException, problem looking up: "java:comp/env"
problem is: javax.naming.NameNotFoundException: Name java:comp is not bound
in this Context
Any other ideas?
Ed