gpt4 book ai didi

javascript - 使用 Spring Security 在 HTML 中登录后重定向到主页

转载 作者:行者123 更新时间:2023-12-03 01:33:27 25 4
gpt4 key购买 nike

我正在尝试登录并将请求重定向到主页。在我当前的状态下,我可以成功登录,但查看空白页面。我不想在 spring/服务器端使用重定向策略。我的 HTML 登录页面如下所示:

<!DOCTYPE html>
<html>
<body>
<form action="/login.html" method="post">
<input type="text" name="username" required>
<input type="password" name="password" required>
<input type="submit" value="Login" />
</form>
</body>
</html>

Spring 安全配置:

http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/**").hasAnyRole(new String[] { "ADMIN" }).and().formLogin().loginPage("/login.html").permitAll();

我想在 HTML 本身中进行一些修复,以便在成功时将请求重定向到主页,在失败时将请求重定向到登录页面本身。我怎样才能做到这一点?我搜索了很多,但没有找到完美的解决方案,如果有人在这里发布答案就好了。

最佳答案

您可以实现一个端点来[检查用户是否已登录][1]。

然后,您可以编写一个 JavaScript 函数来调用该端点并在用户通过身份验证时进行重定向。从 <body onload="yourfunction()"> 调用该函数

[1] How to check if a user is logged in with spring-security?

关于javascript - 使用 Spring Security 在 HTML 中登录后重定向到主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51190985/

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