wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Can't load XSLT file during init 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 » Engineering » XML and Related Technologies
Bookmark "Can Watch "Can New topic

Can't load XSLT file during init

Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
I'm trying to load my XSLT file during my servlet init. This line:
InputStream is = getServletContext().getResourceAsStream(xsltFile);

is giving me a null for the InputStream. Everything looks fine and I can see that xsltFile is the correct pathe to the file. I also tried to generate a URL using .getResource(xsltFile) and got a null for that. Is there some sort of registration or notification that I am missing?

Darryl Failla
Sun Certified Java 2 Programmer
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

No, what you are missing is that the getResourceAsStream() and getResource() methods don't expect to be passed the complete path to the file. They expect to be passed the path to the file, starting with a slash, relative to the web application's context root. (I got this information from the API documentation for the getResource() method of ServletContext.)
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
That did it. Thanks. I wish I would have come here two hours ago.
I agree. Here's the link: http://aspose.com/file-tools
subject: Can't load XSLT file during init
Similar Threads
Load Property file in servlet or jsp
Problem loading Properties file
Spring Classpath
File path issues while reading an xsl file in java
Get path of file in java class in web application