Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Could the path of getResourceAsStream started without "/"?  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,all

It was said that the parameter "path" of the getResourceAsStream(String path) of ServletContext should be specified according to the rules given in getResource in the J2EE API Specification. The specification said that the path of the getResource must begin with a "/" and is interpreted as relative to the current context root.

I wrote two servlet classes and found that the path of getResource must be started with "/" as description, but the path of the getResourceAsStream could be started without "/" either.

My code:


It run suceessfully.

So I wonder whether the path of the getResourceAsStream coule be started without "/". If it could be that, what is it mean? Which directory is the path interpreted?
 
Wei Geng
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there somebody who could answer it?
It puzzled me for several days.
Thanks!
 
Sheriff
Posts: 23582
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me you already did the experiment, almost. So why not find out for yourself? Just change from getResourceAsStream to getResource and you'll get a URL that you can look at.
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!