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 ...
随机推荐
- HomeBrew 安装 PHP7.1(开发笔记)
HomeBrew 安装 PHP7.1 $ brew update $ brew tap homebrew/dupes $ brew tap homebrew/php $ brew update $ b ...
- js日期操作时间看板
var nowTime = null;//获取服务器时间function GetTime() { $.ajax({ url:config._domain + "/AjaxAuctionCen ...
- kali自动化清理缓存和日志
前几天发现kali无法正常开机,启动盘启动进去之后, 发现/var/log/目录下的日志文件太大把硬盘占满了,于是乎... 文件主要是这三个: kern.log : 包含内核产生的日志,有助于在定 ...
- Linux入门(五)linux服务器文件远程管理
1 使用filezila远程管理linux服务器文件 filezila下载地址:https://filezilla-project.org/ filezila默认只能登录普通用户,如果想要root用 ...
- map 理解
键值对 map会将同名的值覆盖掉 public static void main(String[] args) { Map<String,String> maptest=new HashM ...
- lua 中操作系统库
time 和 date 两个函数在lua中实现所有的时钟查询功能. 函数time在没有参数时返回当前时钟的数值.(在许多操作系统中,该数值是距离某个特定时间的秒数). date是time的一种“反函数 ...
- 转:Delphi中destroy, free, freeAndNil, release用法和区别
http://blog.sina.com.cn/s/blog_44fa172f0101cur1.html 1)destroy:虚方法 释放内存,在Tobject中声明为virtual,通常是在其子类中 ...
- SecureCRT - 使用方法和技巧
1. 保活防掉线选项 -> 会话选项 -> 终端勾选 自动重新连接, 发送协议 NO-OP 每60秒 2. 拷贝与粘贴的设置选项 -> Global options -> Te ...
- js 有关字符串的函数 以及一些和字符串有关的知识
JS自带函数 concat 将两个或多个字符的文本组合起来,返回一个新的字符串. var a = "hello"; var b = ",world"; var ...
- 关于WM_NCHITTEST消息
我为了移动一个无标题栏的窗体,使用了WM_NCHITTEST消息,这个消息大概如下: 通常,我们拖动对话框窗口的标题栏来移动窗口,但有时候,我们想通过鼠标在客户区上拖动来移动窗口. 一个容易想到的方案 ...