2017-05-07 13 views
0

私はSpring SecurityとThymeleafで作業しています。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"> 

私はこのURLを取得:

http://localhost:8080/springsecurity/usuario/save?_csrf=&c5cea050-9e39-4220-b7fb-576964def023 

しかし、私の価値は_csrf=c5cea050-9e39-4220-b7fb-576964def023であり、コードの前に&がありませんc5cea050-9e39-4220-b7fb-576964def023

enter image description here

+0

フォームの代わりにとは機能しますか? – Raphael

+0

@ラファエル私は理解していない、何を意味する、私がtryed、それはフォームを提出しない! –

+0

Raphael

答えて

0

通常、あなたは春のセキュリティ、隠されたCSRFの入力と一緒にThymeleafを使用し、自動的に追加されます。そうでない場合は、フォームに以下を追加してください:

<input type="hidden" name="_csrf" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"> 
+0

ありがとうございますが、私はすでにこのコードを使用しようとしていますが、うまくいきませんでした。その後問題を解決しました:action =" @ {/ usuario/save?(_ csrf = $ {_ csrf.token}) " –

+0

@PenaPintadaなぜ閉じますか? – holmis83

+0

問題はありません、私が求めたものを忘れてください。しかし、私はこれをook:http://stackoverflow.com/questions/43635327/how-to-do-this-using-thymleaf –

関連する問題