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