csrf前端代码写一下,集合thymeleaf,登陆页面,和登陆成功后的页面
时间: 2024-02-07 07:38:59 浏览: 75
css实现登陆界面的代码
5星 · 资源好评率100%
登陆页面:
```
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form method="post" th:action="@{/login}">
<div>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<div>
<button type="submit">Login</button>
</div>
</form>
</body>
</html>
```
登陆成功后的页面:
```
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Welcome</title>
</head>
<body>
<h1>Welcome</h1>
<p th:text="'Hello, ' + ${username} + '!'"></p>
<form method="post" th:action="@{/logout}">
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<button type="submit">Logout</button>
</form>
</body>
</html>
```
阅读全文