首页 > 解决方案 > 注销后可以显示一个登录页面

问题描述

我的应用程序使用框架。

这里 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,没有框架)

标签: spring-bootthymeleaf

解决方案


您必须将以下内容添加javascriptlogin.html.

if ( window.location !== window.parent.location ) {
  // We're deeper than one down
  window.parent.location=window.location
}


推荐阅读