2017-02-17 24 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

相关问题