在Wicket中,您可以使用以下方法获取项目的“ 根上下文 ”。
WebApplication.get().getServletContext().getServletContextName()
例如,
public static String getRootContext(){
String rootContext = "";
WebApplication webApplication = WebApplication.get();
if(webApplication!=null){
ServletContext servletContext = webApplication.getServletContext();
if(servletContext!=null){
rootContext = servletContext.getServletContextName();
}else{
//do nothing
}
}else{
//do nothing
}
return rootContext;
}
翻译自: https://mkyong.com/wicket/how-do-get-root-context-of-a-web-application-in-wicket/