login/logout切换
1. 前端按钮
<img border="0" width="18" height="18" src="<%=basePath %>/style/images/top/user.png" /> <font style="font-size:11px; font-family:Microsoft YaHei"> ${usersession.name }
<c:forEach items="${usersession.roles }" var="r">
${r.name }
</c:forEach>
</b></font>
<%if(session.getAttribute("usersession")!=null){%>
<input type="button" value="Log Out" onclick="javascript:logout()" style="color:#2c3e50; font-size:12px;font-weight:bold; border-radius:3px; vertical-align:middle;height:20px; width:70px; "/>
<%}else {%>
<input type="button" value="Log In" onclick="javascript:login()" style="color:#2c3e50; font-size:12px;font-weight:bold; border-radius:3px; vertical-align:middle;height:20px; width:70px; "/>
<%} %>
2. js函数
<script>
function logout(){
$.getJSON("/portal/user/logout?rand="+Math.random(),function(data){
if("success"==data.result){
parent.location.href="/portal/home/index";
}
else{
alert("logout failure!");
}
});
}
function login(){
window.open("/portal/user/loginUI","_parent");
}
</script>
3. controller端实现
@RequestMapping("/login")
public String login(String loginName, String password, HttpSession session,HttpServletRequest request){
//session.invalidate();
User user = userService.findByLoginNameAndPassword(loginName, password);
if(user == null){
request.setAttribute("loginError", "用户名或者密码错误");
return "/userController/loginUI";
}
else{
session.setAttribute("usersession", user);
}
return "/homeController/index";
}
@RequestMapping("/logout")
public String logout( HttpSession session,HttpServletResponse response){
session.removeAttribute("usersession");
session.invalidate();
JSONObject data = new JSONObject();
try {
data.put("result", "success");
} catch (Exception e) {
System.out.println(e.getMessage());
}
PrintWriter out = null;
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try {
out=response.getWriter();
out.write(data.toString());
out.flush();
out.close();
return null;
} catch (IOException e) {
e.printStackTrace();
}
//return "/userController/logout";
return "/homeController/index";
}
login/logout切换的更多相关文章
- Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken
在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...
- [Node] Stateful Session Management for login, logout and signup
Stateful session management: Store session which associate with user, and store in the menory on ser ...
- FaceBook登陆API -- Login with API calls
Login with API calls Related Topics Understanding sessions FBSession Error handling FBError FBLoginC ...
- Yarn 和 Npm 命令行切换 摘录
原文作者: @Gant Laborde原文地址: https://shift.infinite.red/np...中文翻译: @文蔺译文地址:http://www.wemlion.com/2016/n ...
- Angular--页面间切换及传值的四种方法
1. 基于ui-router的页面跳转传参(1) 在AngularJS的app.js中用ui-router定义路由,比如现在有两个页面,一个页面(producers.html)放置了多个produce ...
- Spring Security笔记:使用数据库进行用户认证(form login using database)
在前一节,学习了如何自定义登录页,但是用户名.密码仍然是配置在xml中的,这样显然太非主流,本节将学习如何把用户名/密码/角色存储在db中,通过db来实现用户认证 一.项目结构 与前面的示例相比,因为 ...
- [转]Angular: Hide Navbar Menu from Login page
本文转自:https://loiane.com/2017/08/angular-hide-navbar-login-page/ In this article we will learn two ap ...
- Roundcube login via PHP script
目前正在整合 roundcube 1.0.5 的邮件系统和其他系统,想取消登录过程,发现了这个,先赞一个! 原文地址: http://blog.philippheckel.com/2008/05/16 ...
- [Firebase] 3. Firebase Simple Login Form
Using $firebaseSimpleLogin service. Here we use three methods for login, logout, register and getCur ...
随机推荐
- CSS兼容的一些问题
DIV+CSS网页布局这是一种趋势,我也开始顺应这股趋势了,不过在使用DIV+CSS网站设计的时候,应该注意css样式兼容不同浏览器问题,特别是对完全使用DIV+CSS设计的网页,就应该更注意IE6 ...
- HDU 4990 Reading comprehension
快速幂 #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #i ...
- 《JS权威指南学习总结--7.10 数组类型》
内容要点: 一.数组类型 判断它是否为数组通常非常有用.在ES5中,可以使用Array.isArray()函数来做这件事情: Array.isArray([]); //=>true Array. ...
- Ctrl+Alt+T恢复启动Ubuntu默认终端
对于Ubuntu14.04,如果安装了terminator,那么快捷键Ctrl+Alt+T将不会启动自带的terminal,而是启动安装的terminator,如果想恢复回来,可以执行以下命令: su ...
- 帝国cms
1:帝国cms 设置安装完成 2: 帝国cms 封面页模板 内容页模板和列表页模板完成
- Web程序和应用程序服务器[转]
转自:http://hi.baidu.com/lclkathy/blog/item/dae3be36763a47370b55a970.html 一 常见的WEB服务器和应用服务器 在UNIX和LINU ...
- 《高性能Javascript》读书笔记-3
第三章 DOM编程 把dom和js 各自想象为一个岛,他们之间用收费的桥梁链接,每次访问dom都必须途径这座桥收取过路费,访问次数多费用就高了.所有必须减少来往次数. innerHtml 与dom比较 ...
- Lua入门基础
什么是Lua Lua 是一个小巧的脚本语言.是巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro)里的一个研究小组,由Rober ...
- rabbitmq(1)-入门
参考: documentation: https://www.rabbitmq.com/documentation.htmldemo: https://www.rabbitmq.com/getstar ...
- 直接粘贴代码到网络上:command-line pastebins
软件作用 直接把管道里面的文字内容传到网站上面,然后反馈一个地址可以读取内容. 同类软件 wgetpaste dpaste pastebin pasteie 用法 介绍wgetpaste为例: GEN ...