• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using getResourceAsStream() in Servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

What are you passing in as the parameter? Where is the file located?
[ October 06, 2008: Message edited by: Ulf Dittmer ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic