File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring 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: 63540

Never hard-code the context path. Use:


(assumes JSP 2.0)

[Asking smart questions] [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!