Spring 提交表单时出现InvalidCsrfTokenException
我在一个基于spring的web应用程序(版本4.1.6.RELEASE,spring security 4.0.0.RELEASE)中工作,我收到了一个错误Spring 提交表单时出现InvalidCsrfTokenException,spring,jsp,spring-security,csrf,Spring,Jsp,Spring Security,Csrf,我在一个基于spring的web应用程序(版本4.1.6.RELEASE,spring security 4.0.0.RELEASE)中工作,我收到了一个错误InvalidCsrTokenException:在提交表单(POST方法)后,在请求参数“\u CSRF”或标题“X-CSRF-Token”上发现了无效的CSRF令牌“null”。。根据“Spring Security会自动为您使用的任何标记插入一个CSRF表单字段”,那么我为什么会得到这个异常呢? 提前谢谢。 这是我的spring安全
InvalidCsrTokenException:在提交表单(POST方法)后,在请求参数“\u CSRF”或标题“X-CSRF-Token”上发现了无效的CSRF令牌“null”。
。根据“Spring Security会自动为您使用的任何
标记插入一个CSRF表单字段”,那么我为什么会得到这个异常呢?提前谢谢。
这是我的spring安全配置:
这是我的表单的定义(不包括它包含的字段):
任何帮助都将不胜感激问题的出现是因为您使用的是一个多部分表单。请参见此处接受的答案:
Hi@Smogers,非常感谢您提供此链接,请将您的评论作为答案发布,我会接受的,regardsok,很高兴它解决了您的问题
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<http use-expressions="true" disable-url-rewriting="true">
<headers>
<frame-options/>
<xss-protection/>
<hsts/>
</headers>
<csrf/>
<intercept-url pattern="/welcome" access="isAuthenticated()" />
<!-- some others urls to intercept -->
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
<session-management>
<concurrency-control max-sessions="1" expired-url="/login" />
</session-management>
</http>
<form:form action="myaction" method="post" enctype="multipart/form-data" id="formId" modelAttribute="myBean">
</form:form>