Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Paths to use for links" Watch "Paths to use for links" New topic
Author

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
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Never hard-code the context path. Use:

${pageContext.request.contextPath}

(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!
 
jQuery in Action, 2nd edition
 
subject: Paths to use for links