web项目配置多登录页出现的超时问题

因工作需要2个登录页面,配置2个登录页面后发现session超时后不能跳转到特定的登录页,只能跳转到一个登录页,不能区分跳转。

解决方式:因为session超时,不能获取有用信息,考虑使用cookie来保存登录原始页面,用于超时判断跳转到那个登录页。考虑到因为都跳转到默认登录页,就在登录页面的方法中进行判断,来区分跳转。登录时保存登录标识到cookie中。代码入下。其中login_cookie用于区分是从哪个登录页面进入系统的。

第一个访问登录页面的方法

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(HttpServletRequest request) {
   Cookie[] cs = request.getCookies();
   if(cs!=null && cs.length>0){
      for(Cookie cookie:cs){
         if("login_cookie".equals(cookie.getName())){
            if("zhongke".equals(cookie.getValue())){
               return "login/otherLogin";
            }
         }
      }
   }
   return "login/login";
}

第一个登录入口

@RequestMapping(value = "/doLogin", method = RequestMethod.POST)
public String login(String dlyhid, String yhmm, String code, ModelMap modelMap,HttpServletRequest request,HttpServletResponse response) throws Exception {
   Cookie[] cookies = request.getCookies();
   if(cookies==null){
      Cookie cookie = new Cookie("login_cookie", "rjxx");
      cookie.setPath("/");
      response.addCookie(cookie);
   }else{
      boolean flag = true;
      for(Cookie cookie:cookies){
         if("login_cookie".equals(cookie.getName())){
            cookie.setValue("rjxx");
            cookie.setPath("/");
            response.addCookie(cookie);
            flag = false;
            break;
         }
      }
      if(flag){
         Cookie cookie = new Cookie("login_cookie", "rjxx");
         cookie.setPath("/");
         response.addCookie(cookie);
      }
   }
}

第二个登录入口的方法

@RequestMapping(value = "/doLogin", method = RequestMethod.POST)
public String login(String dlyhid, String yhmm, String code, ModelMap modelMap,HttpServletRequest request,HttpServletResponse response) throws Exception {
   Cookie[] cookies = request.getCookies();
   if(cookies==null){
      Cookie cookie = new Cookie("login_cookie", "zhongke");
      cookie.setPath("/");
      response.addCookie(cookie);
   }else{
      boolean flag = true;
      for(Cookie cookie:cookies){
         if("login_cookie".equals(cookie.getName())){
            cookie.setValue("zhongke");
            cookie.setPath("/");
            response.addCookie(cookie);
            flag = false;
            break;
         }
      }
      if(flag){
         Cookie cookie = new Cookie("login_cookie", "zhongke");
         cookie.setPath("/");
         response.addCookie(cookie);
      }
   }



}

转载于:https://my.oschina.net/sky2008/blog/1820937

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值