gpt4 book ai didi

spring - ${_csrf.parameterName} 和 ${_csrf.token} 返回 null

转载 作者:行者123 更新时间:2023-12-01 16:23:44 25 4
gpt4 key购买 nike

对我来说,CSRF token 没有生成......我搜索了很多链接仍然没有找到解决方案

收到此错误

Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:url value="/j_spring_security_check" var="postUrl"/>
<form action="${postUrl}" method="post" >
<c:if test="${param.error != null}">
<p>Invalid username and password.</p>
</c:if>
<c:if test="${param.logout != null}">
<p>You have been logged out.</p>
</c:if>
<p>
<label for="username">Username</label>
<input type="text"
id="username" name="username" />
</p>
<p>
<label for="password">Password</label> <input type="password"
id="password" name="password" />
</p>


<input type="text"
name="${_csrf.parameterName}"
value="${_csrf.token}" />

<button type="submit" class="btn">Log in</button>
</form>
</body>
</html>

在 pom.xml 中

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>

最佳答案

对我来说,我遇到了同样的错误,问题是我在 web.xml 中缺少以下配置,

<!-- Spring Security Filter -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

关于spring - ${_csrf.parameterName} 和 ${_csrf.token} 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30983403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com