Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 42414 invoked from network); 3 Jan 2003 20:55:40 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 3 Jan 2003 20:55:40 -0000 Received: (qmail 12830 invoked by uid 97); 3 Jan 2003 20:56:39 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 12804 invoked by uid 97); 3 Jan 2003 20:56:38 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 12792 invoked by uid 98); 3 Jan 2003 20:56:37 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: Fri, 3 Jan 2003 12:55:11 -0800 (PST) From: "Craig R. McClanahan" To: Tomcat Users List Subject: Re: Why a JNDI URL from getServletConfig().getResource() in Tomcat In-Reply-To: <3E15F3B4.1050106@woz.com> Message-ID: <20030103125136.D24439-100000@icarus.apache.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Fri, 3 Jan 2003, Trevor Porter wrote: > Date: Fri, 03 Jan 2003 12:33:56 -0800 > From: Trevor Porter > Reply-To: Tomcat Users List > To: tomcat-user@jakarta.apache.org > Subject: Why a JNDI URL from getServletConfig().getResource() in Tomcat > > I'm trying to read in a configuration file I have stored in my /WEB-INF > directory from my servlet init() using > getServletConfig().getResource(...) as follows: > > public void init() throws ServletException > { > ... > > String config = getServletConfig().getInitParameter("config"); > URL url = getServletContext().getResource(config); > ... > } > > If I set the config init parameter to something like this (the > /WEB-INF/test.xml file does exist): > > > config > /WEB-INF/test.xml > > > I get back the following jndi URL from getResource(): > > jndi:/localhost/sandbox/WEB-INF/test.xml > > The same code running under resin returns a file URL as I would expect. The format of the URL being returned is totally up to the container -- the only requirement is that the container must be able to resolve this URL and give you back an input stream from it. (Besides, a file: URL would not work if you ran the webapp directly from a WAR file :-). > The problem is that if I replace the getResource() call with a > getResourceAsStream() under tomcat, the input stream will be empty. Can > anyone out there explain this behavior and how to work around it? As long as the "/WEB-INF/test.xml" resource exists in your webapp, my experience has been that Tomcat always lets you read it. Indeed, Struts relies on this to read its own config file, and lots of Struts apps run quite happily on Tomcat. Could you create a small test case that illustrates the problem, and add it as an attachment to a bug report in the bug tracking system? http://nagoya.apache.org/bugzilla/ Craig -- To unsubscribe, e-mail: For additional commands, e-mail: