How to get context path in Wicket


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:


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/");


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