How to get context path in Wicket

Updated

In Wicket the context related information can be fetched from the ServletContext class. The easiest way to access the this class is through the WebApplication class like this:

WebApplication.get().getServletContext()

So, for example, if you need the context path to a ExternalLink you would create it like this:

String contextPath = WebApplication.get().getServletContext().getContextPath();
ExternalLink externalLink = new ExternalLink("link", contextPath + "/otherservlet/");

Comments

Did you find this article helpful? Or are there parts that need some improving? Write your comment below and let me know what you think!

comments powered by Disqus