Context-aware URLs in JSP

Posted on 11-01-2013 12:48 by graham
If you want to build a context aware URL in JSP, i.e. such that includes the application's context and works no matter with which context the application is deployed, use the ${pageContext.request.contextPath} variable:
<a href="${pageContext.request.contextPath}/some/action">...</a>

If your application is deployed with context, for example, my-app, then the URL will be turned to:
<a href="/my-app/some/action">...</a>


Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems