This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JSP and the fly likes Paths to use for links Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Paths to use for links" Watch "Paths to use for links" New topic

Paths to use for links

Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
In the JSP include files for my project, I use absolute path (starts with /) for the links since those files are included in JSPs that are located in different levels. However, a link such as "/about" ended up as "http://localhost:8080/about". To solve the problem, currently I included the name of the webapps in the path, such as "/myapp/about", but those links would become broken when deployed to a production server.

Is there a better solution?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63044

Never hard-code the context path. Use:


(assumes JSP 2.0)

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Thanks Bear!
I agree. Here's the link:
subject: Paths to use for links
It's not a secret anymore!