• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Paths to use for links

 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65119
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never hard-code the context path. Use:

${pageContext.request.contextPath}

(assumes JSP 2.0)
 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic