session的登录与注销

文章来源:http://cczakai.iteye.com/blog/1575895

Java代码   收藏代码
  1. protected void clearSession() {  
  2.   
  3.     SessionMap sessionMap = (SessionMap) ActionContext.getContext()  
  4.             .getSession();  
  5.     try {  
  6.         sessionMap.clear();  
  7.     } catch (Exception e) {  
  8.         //  
  9.     }  
  10.   
  11.     HttpSession httpSession = this.getServletRequest().getSession();  
  12.     try {  
  13.         httpSession.invalidate();  
  14.     } catch (Exception e) {  
  15.         //  
  16.     }  
  17. }  

 

 

doLogin

 

Java代码   收藏代码
  1. public String doLogin() {  
  2.         clearSession();  
  3.         String loginUsername = this.getLoginUsername();  
  4.         String loginPassword = this.getLoginPassword();  
  5.         if (StringUtils.isBlank(loginUsername)) {  
  6.             setMessage("用户名必填项");  
  7.             return INPUT;  
  8.         } else if (StringUtils.isBlank(loginPassword)) {  
  9.             setMessage("密码必填项");  
  10.             return INPUT;  
  11.         }  
  12.   
  13.         try {  
  14.             setSessionAttribute(SESSION_ATTRIBUTE_KEY_USER,user);  
  15.                     setCookiesAttribute(COOKIES_ATTRIBUTE_KEY_EMPLOYEE_NO, loginUsername);  
  16.             return "home";  
  17.         } catch (WebApplicationRuntimeException e) {  
  18.             this.setMessage(e.getMessage());  
  19.         }  
  20.   
  21.         return INPUT;  
  22.     }  

 

 

loginout

 

Java代码   收藏代码
  1. public String execute() {  
  2.     try {  
  3.         clearSession();  
  4.         ReserverCookie reserverCookie = new ReserverCookie();  
  5.         reserverCookie.removeCookie(this.getServletRequest(), getServletResponse());  
  6.     } catch (Exception e) {  
  7.   
  8.     }  
  9.     return "login";  
  10. }  

 

 

Java代码   收藏代码
  1. public void removeCookie(HttpServletRequest request,  
  2.         HttpServletResponse response) {  
  3.     Cookie cookie = getCookie(request);  
  4.     if (cookie != null) {  
  5.         cookie = new Cookie(COOKIE_NAME, "");  
  6.         cookie.setMaxAge(0);  
  7.         cookie.setValue("");  
  8.         cookie.setPath("/");  
  9.         cookie.setDomain(CSAIR_COM);  
  10.         response.addCookie(cookie);  
  11.     }  
  12. }  




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值