Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何将@Value注入thymeleaf内联javascript_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Spring mvc 如何将@Value注入thymeleaf内联javascript

Spring 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

我有一个使用thymeleaf的内联javascript

<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接口的引用。我想要得到的是我的应用程序的上下文根;