• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getResource() n getResourceAsStream()

 
mysha ahamed
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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..
Thnx..
 
Severin Stoeckli
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.

/Severin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic