Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding URL

 
Kapil Mishra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,i have one doubt regarding URL.

On page 129 of HFJS,the something written like-"The getResourceAsStream() requires you to start with a forward slash (“/”) , which represents the root of your web app. "

while on page 136 there is-The forward slash at the beginning means “relative to the root of this web Container”.

So please anyone clarify it,what does this forward slash mean in servlet and wat in DD......


 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both mean the same thing to me. A forward slash in the beginning means the path is to be interpreted as starting from the web app root folder. So if you have a value in DD which is /jsp/my.jsp and the web app root folder is myApp, then the value in DD will mean myApp/jsp/my.jsp...
 
Kapil Mishra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ankit thnx for reply...

but i think root of web container means outside of your app means in webapps folder of tomcat directory...and root of app means your app directory....

correct me if i am wrong....

Thnxx
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kapil Mishra wrote:
but i think root of web container means outside of your app means in webapps folder of tomcat directory...and root of app means your app directory....

I think you are talking about "response.sendRedirect()" ? In that case if the relative URL starts with "/" then the URL being built will be relative to the web container.
 
Amru Jahagirdar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meaning of both the sentences is same.
root of the web container here, means with respect to your web application.

Anything you specify as '/PathToTheFile' is interpreted as

'WebApplicationName/PathToTheFile'
 
Kapil Mishra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes Vijitha,you got it....

In response.sendRedirect() "/" means relative to container while in other, "/" means relative to application..

I want to know why this inconsistency about this forward slash "/" there ??
 
Darryl Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the method endodeURL also with a / as the argument and this is also generated a URL that is the root of the web container. The spec mentions nothing regarding where this method should be relative to.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic