Spring mvc 如何将@Value注入thymeleaf内联javascript
我有一个使用thymeleaf的内联javascriptSpring mvc 如何将@Value注入thymeleaf内联javascript,spring-mvc,spring-boot,thymeleaf,Spring Mvc,Spring Boot,Thymeleaf,我有一个使用thymeleaf的内联javascript <script th:inline="javascript"> /*<![CDATA[*/ var contextPath = [[@Value("#{servletContext.contextPath}")]]; /*]]>*/ </script> /**/ 当我的文档被解析并发送到客户端时,这就是打印的内容 <script> /*<![C
<script th:inline="javascript">
/*<![CDATA[*/
var contextPath = [[@Value("#{servletContext.contextPath}")]];
/*]]>*/
</script>
/**/
当我的文档被解析并发送到客户端时,这就是打印的内容
<script>
/*<![CDATA[*/
var contextPath = </script>
/*
我试过这个
<script th:inline="javascript">
/*<![CDATA[*/
var contextPath = [[${servletContext.contextPath}]];
/*]]>*/
</script>
/**/
但我得到了同样的结果
servletContext是对
javax.servlet.servletContext
接口的引用中解释了您需要什么
试试这个:
var contextPath = /*[[${#ctx.servletContext.contextPath}]]*/ null;
谢谢,但是servletContext是对javax.servlet.servletContext接口的引用。我想要得到的是我的应用程序的上下文根;