什么是获取Thymeleaf $ {pageContext.request.contextPath}的语法 [英] What is the Syntax to get Thymeleaf ${pageContext.request.contextPath}

查看:663
本文介绍了什么是获取Thymeleaf $ {pageContext.request.contextPath}的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找类似JSTL的语法 $ {pageContext.request.contextPath}



我做了一个javascript代码来改变表单上的action属性来调用spring控制器上的edit方法,所以问题是下面的代码不能在不调用Context的情况下工作,如 $ {pageContext。 request.contextPath} /edit.html

I have searched hard for a syntax like the JSTL one ${pageContext.request.contextPath},

I did made a javascript code to change the action attribute on the form to call the edit method on the spring controller so, the problem is the below code dont work without calling the Context first like ${pageContext.request.contextPath}/edit.html

<script th:inline="javascript">
    function edit() {
        document.getElementById("user_form").action = "/edit.html";
    }
</script>

那么调用 Thymeleaf上下文路径的语法是什么?

so what is the Syntax to call Thymeleaf context path?

推荐答案

在Thymeleaf相当于JSP的 $ {pageContext.request.contextPath} /edit.html @ {/ edit.html}

In Thymeleaf the equivalent of JSP's ${pageContext.request.contextPath}/edit.html would be @{/edit.html}

查看部分Thymeleaf文档了解更多详情

Check out this part of the Thymeleaf documentation for more details

In你会写你的情况:

In your case you would write :

<script th:inline="javascript">
    function edit() {
        var link = /*[[@{/edit.html}]]*/ 'test';
        document.getElementById("user_form").action = link;
    }
</script>

/ * [[ - <$ Thymeleaf使用c $ c>]] * / 语法来评估Javascript使用的变量,如果要静态加载,则不会破坏脚本。查看部分更多细节的文档

The /*[[ - ]]*/ syntax is used by Thymeleaf to evaluate variables used by Javascript, without breaking the script if that where to be statically loaded. Check out this part of the documentation for more details

这篇关于什么是获取Thymeleaf $ {pageContext.request.contextPath}的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆