三、安全退出的设计
安全退出的需求
用户在任意的业务页面,点击"退出"按钮,弹出确认退出的模态窗口;用户在确认退出的模态窗口,点击"确定"按钮,完成安全退出的功能.
*安全退出,清空cookie,销毁session
安全退出流程图
一、UserController
1.安全退出跳转到登录页面,通过重定向返回到首页,首页跳转到登录页面
@RequestMapping("/settings/qx/user/logout.do")public String logout(HttpServletResponse response,HttpSession session) {//清空cookie//删除之前cookieCookie c1 = new Cookie("loginAct", "1");//账号//设置生命周期c1.setMaxAge(0);//保存到浏览器response.addCookie(c1);Cookie c2 = new Cookie("loginPwd", "1");//密码//设置生命周期c2.setMaxAge(0);//保存到浏览器response.addCookie(c2);//删除Sessionsession.invalidate();return "redirect:/";}
二、index.jsp
src/main/webapp/WEB-INF/pages/workbench/index.jsp
给退出按钮添加单击事件,跳转到controller前端控制器
$("#logoutBtn").click(function () {//发送同步请求window.location.href='settings/qx/user/logout.do';});