0
我正在使用Spring Security和Thymeleaf。如何使用百里香叶做到这一点?
下面的代码使用JSP:
<c:url var="save" value="/usuario/save?${_csrf.parameterName}=${_csrf.token}"/>
<form:form modelAttribute="usuario" action="${save}" method="post"
enctype="multipart/form-data">
这是使用Thymeleaf我的代码,它不工作:
<form action="#" method="post" th:action="@{/usuario/save?_csrf=(${_csrf.token})}" th:object="${usuario}" enctype="multipart/form-data">
我得到这个网址:
http://localhost:8080/springsecurity/usuario/save?_csrf=&c5cea050-9e39-4220-b7fb-576964def023
但我的价值是_csrf=c5cea050-9e39-4220-b7fb-576964def023
没有&
之前的代码c5cea050-9e39-4220-b7fb-576964def023
它可以与而不是表单一起使用吗? –
Raphael
@拉斐尔我不明白,什么意思,当我尝试时,它不提交表格! –
回答
通常,当你使用Spring Security一起使用Thymeleaf,隐藏CSRF输入会自动添加。如果不是,请尝试在您的表单中添加以下内容:
来源
2017-05-08 06:50:39 holmis83
谢谢,但我已经尝试使用这段代码,但它不起作用,于是我用th:action =”@ {/ usuario/save?(_ csrf = $ {_ csrf.token})}“ –
@PenaPintada为什么关闭? – holmis83
没问题,忘记我要求的。但是,哦,这个:http://stackoverflow.com/questions/43635327/how-to-do-this-using-thymleaf –
相关问题