File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes using getResourceAsStream() in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "using getResourceAsStream() in Servlet" Watch "using getResourceAsStream() in Servlet" New topic
Author

using getResourceAsStream() in Servlet

bhupesh belchandan
Greenhorn

Joined: Apr 07, 2008
Posts: 1
hi......

I want to read xml files stored in resources folder of my web application,
so I am using servlet's getResourcesAsStream() which return InputStream,
but I am not getting the Stream of the xml file and getting a NullPointerException.

please help to solve this.....!

Thank you..


NJOY..........!<br />Bhupesh<br />NaCon
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Welcome to JavaRanch.

What are you passing in as the parameter? Where is the file located?
[ October 06, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Jerwin Louise Uy
Ranch Hand

Joined: Oct 27, 2007
Posts: 75
Based on the javadoc of ServletContext, the only way it will return null is if the resource does not exist in the path you supplied.

Please verify the the resource your are trying to load exists. If it does, then verify if you are passing the correct parameters.

The rules governing the path of the parameter in this function is referred to in the getResource function of the ServletContext. Please refer to the javadoc.

javax.servlet.ServletContext

Usually, it should start with "/" and should be relative to the current context root where the ServletContext object is created by the container.

Regards.


Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
email: jerwin.uy@incuventure.net
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using getResourceAsStream() in Servlet
 
Similar Threads
Escape Encoding for XML attribute
response xml
each time encryption gives different result......??
MQ Exception --- 2033 error
hi friends i am getting exception when i am using jasper reports