| Author |
Problem reading env-entry
|
Ed Faulk
Greenhorn
Joined: Sep 22, 2004
Posts: 1
|
|
I have several servlets in an application and they need to access some information in the environment entries. I could, of course, put the entry in each servlet descriptor, but having them in one place is so much more convenient. In any case, I seem to be unable to access the environment context. 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); sName = "MessageOption"; String envVar = (String) envCtx.lookup(sName); out.println("envVar: " + envVar); } catch (NamingException e) { out.println("NamingException, problem looking up: \"" + sName + "\"<br>problem 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 ideas? Ed [ September 22, 2004: Message edited by: Ed Faulk ]
|
 |
 |
|
|
subject: Problem reading env-entry
|
|
|