2017-02-17 23 views

回答

0

內部視圖:

在Thymeleaf,JSP的${pageContext.request.contextPath}相當於將@{ },即。如果你在jsp中有一個url,如${pageContext.request.contextPath}/login那麼在thymeleaf中它將是@{/login}。該/ [ - ] /語法使用Thymeleaf在javascript來評估變量,如var url = /*[[@{/login}]]*/;

編號:http://www.thymeleaf.org/doc/articles/standardurlsyntax.html

內部處理器類別:

首先,你需要轉換的上下文到IWebContext,然後獲取調用getRequest的HttpServletRequest對象,最後通過調用request.getContextPath()來獲取上下文路徑。您可能想要使用instanceof運算符來檢查上下文是否爲IWebContext的類型,我在此跳過了這一點。

final HttpServletRequest request = ((IWebContext) context).getRequest(); 
    System.out.println("contextpath: " + request.getContextPath()); 
+0

好的,但這是我已經在我的意見中使用。我想在我的自定義處理器的java類中檢索這些信息。 –

+0

對不起我的誤解。回答更新,現在檢查。 :-) – mhshimul

相關問題