aspose file tools*
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
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: 61413
    
  67

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Paths to use for links