GeeCON Prague 2014*
The moose likes Servlets and the fly likes When to use Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "When to use "/" in front of a Path ?" Watch "When to use "/" in front of a Path ?" New topic
Author

When to use "/" in front of a Path ?

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
when to use path "/net/major/javaclass" , "net/major/javaclass"??

When to use "/" in front of a Path ?


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Always. Otherwise the path is page-relative and that's a recipe for failure.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
path is page-relative


what is meant by "path is page-relative"??,Could you please explain this??
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

jacob deiter wrote:
what is meant by "path is page-relative"??


related to the current url .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

seetharaman venkatasamy wrote: related to the current url .

Exactly. Which is fine for web sites consisting of static HTML pages. But can be a big problem for web apps where URLs are mapped to servlets whose URLs do not reflect folders in the file system.
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Sorry .I am really confused.Please explain with more details??
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Jacob,

Sorry .I am really confused.Please explain with more details??


say your servlet url pattern is as below

<url-pattern>/login/ProcessLogin</url-pattern>

and say forward to a jsp , if you dont use "/" , it assumes to refer inside /login and search for jsp inside login directory. Use of "/" make sure that you are referencing from Context path.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When to use "/" in front of a Path ?