spring-boot - 注销后可以显示一个登录页面
问题描述
我的应用程序使用框架。
这里 index.html:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${appName}">Template title</title>
<link th:href="@{/public/style.css}" rel="stylesheet"/>
</head>
<frameset cols="15%,*">
<frame src="navigator" name="navigator" scrolling="no" noresize/>
<frame src="welcome" name="main"/>
</frameset>
</html>
这里登录控制器:
@Controller
public class LoginController {
@Value("${spring.application.name}")
private String appName;
private static Logger logger = LogManager.getLogger(LoginController.class);
/*-
@RequestMapping("/")
@ResponseBody
public String index() {
return "Hello!";
}
*/
// Login form
@RequestMapping("/login.html")
public String login(Model model) {
logger.info("open_login.html");
model.addAttribute("appName", appName);
return "login.html";
}
// Login form with error
@RequestMapping("/login-error.html")
public String loginError(Model model) {
model.addAttribute("appName", appName);
model.addAttribute("loginError", true);
return "login.html";
}
}
结果:
成功登录后(显示帧)
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
private static Logger logger = LogManager.getLogger(CustomLogoutSuccessHandler.class);
@Override
public void onLogoutSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication authentication)
throws IOException, ServletException {
request.getSession().invalidate();
response.sendRedirect(request.getContextPath() + "/login.html");
}
}
但这里是按注销后的结果
但我只需要一页(login.html,没有框架)
解决方案
您必须将以下内容添加javascript
到login.html
.
if ( window.location !== window.parent.location ) {
// We're deeper than one down
window.parent.location=window.location
}
推荐阅读
- python - 通过子字符串信息查找 DataFrame 中的所有行
- firebase - 当页面数据未从 Firebase 完全加载时显示加载指示器/微调器 - Flutter
- javascript - 反应原生应用程序中的重新渲染太多,我该怎么办?
- ios - SwiftUI 中的小部件URL
- php - 从 PHP Web 应用程序连接到本地/本地 Active Directory
- powershell - 向PowerShell中的多个地址发送电子邮件
- c++ - 运行时 C++ 数学无法按预期工作
- delphi - 调整表格大小以适合其标题
- vim - vim range .+1,$ 包含当前行,对一行影响太大
- database - Symfony:更新数据库模式以反映已删除的表