WicketでWebアプリケーションのルートコンテキストを取得する方法

WicketでWebアプリケーションのルートコンテキストを取得する方法

Wicketでは、次の方法を使用して、プロジェクトの「root context」を取得できます。

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;

}