Wasn't one of the 3.2.2 changes that you could not request URLs from the
WEB-INF directory?  Possibly its just that and not really all relative URLs.

Brian Flynn

-----Original Message-----
From: Stevenson, Chris (SSABSA) [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 2:44 AM
To: [EMAIL PROTECTED]
Subject: [BUG T322] Bug in getServletContext().getResource() for
relative URLs



Bugzilla is down so I am forced to send this to the list:

Relative URLs from a servlet resource do not work (Tomcat 3.2.2).

I have the following code in a Servlet:

URL propURL = getServletContext().getResource(
"/WEB-INF/connection.properties" )
URL configURL = new URL( url, "config.xml" );

The servlet throws a FileNotFoundException on configURL.getInputStream() 
some diagnostic info follows:

Could not load configuration file: file:persist.config.xml
propURL: file:F:\tomcat\tomcat-dev\webapps\ore\WEB-INF\connection.properties
configURL: persist.config.xml

Apache Tomcat/4.0-b5 works perfectly, but its using jndi.

Also, if I do the following:

URL configURL = new URL( url, "config.xml" );
configURL = new URL( configURL.toString() );

it works!

java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

Full Exception is
java.io.FileNotFoundException: persist.config.xml (The system cannot find
the file specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:64)
        at
sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:6
9)
        at
sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection
.java:133)
        at java.net.URL.openStream(URL.java:798)
        at ssabsa.control.Controller.<init>(Controller.java:52)
        at ssabsa.control.Controller.getInstance(Controller.java:74)
        at ssabsa.ore.WoreServlet.init(WoreServlet.java:47)
        at javax.servlet.GenericServlet.init(GenericServlet.java:258)
        at
org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
        at org.apache.tomcat.core.Handler.init(Handler.java:215)
        at
org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:296)
        at
org.apache.tomcat.context.LoadOnStartupInterceptor.contextInit(LoadOnStartup
Interceptor.java:130)
        at
org.apache.tomcat.core.ContextManager.initContext(ContextManager.java:491)
        at
org.apache.tomcat.core.ContextManager.init(ContextManager.java:453)
        at org.apache.tomcat.startup.Tomcat.execute(Tomcat.java:195)
        at org.apache.tomcat.startup.Tomcat.main(Tomcat.java:235)


Reply via email to