• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

getResource() n getResourceAsStream()  RSS feed

Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Iam not able to understand the real meaning of getResource() n getResourceAsStream()methods in ServletContext.

In the api its given ServletContext.getResource()):

The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a RequestDispatcher instead to include results of an execution.
This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.

In HFSJ its given tht these methods may not be used to access resources in jar files instead v shuld use classloader's getResource() n getResourceAsStream()methods .

But in the api spec its given :Resources can be located in a .war file.

Can anyone pls expalin me the main purpose of these methods n distiction b/w classloaders methods..
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the ClassLoader's getResourceAsStream searchs your resource in the classpath, according to the rules of the classLoader.

the Servlet's getResourceAsStream expects a URL to the resource and can access a .war file, but not something in a .jar -file inside the .war file.

Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!