wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Problem reading env-entry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Problem reading env-entry" Watch "Problem reading env-entry" New topic
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 ]
 
Consider Paul's rocket mass heater.
 
subject: Problem reading env-entry
 
Similar Threads
A simple JNDI question....
Jndi - can't find
Resource injection for env entry in the field
NoInitialContextException
Please Help! I Have Worked On IT For Days.