• 验证登录超时,在登录后跳转超时时的页面


    1.问题,在开发时每跳转一个页面时会验证是否登录状态,如果没有登录就会跳转到登录页面,在登录后常常需要再跳回刚刚的页面

    2.代码流程展示

    2.1登录ajax代码展示:

      function sloginSubmit() {
                var mobile = $('#smobile').val();
                var password = $('#spassword').val();
                if(mobile.length==0){
                    errorTips("手机号有误",2000);
                    return;
                }
                if( password.length==0){
                    errorTips("请输入验证码",2000);
                    return;
                }
                $.ajax({
                    type : 'POST',
                    url : 'sloginSubmit.html',
                    data: {"mobile":mobile,"password":password},
                    success : function(data) {
                        if(data.code==0){
                            if(data.message.length>0){
                                location.href="${request.contextPath}"+data.message; //这里在登录的时候如果返回的有路径则执行路径的页面跳转
                            }else{
                                location.href="${request.contextPath}/wx/index.html";
                            }
                        }else{
                            errorTips(data.message,2000);
                        }
                    },
                    error : function(data) {
                        errorTips(data.message,2000);
                    }
                });
            }

    2.2.登录部分代码

     jsonMessageView = new JSONMessageView(BusinessConstant.OK,"",null);
                if(request.getSession().getAttribute("requestPath")!=null){
                    String path = (String) request.getSession().getAttribute("requestPath");
                    jsonMessageView = new JSONMessageView(BusinessConstant.OK,path,null);
                }
                return jsonMessageView;

    2.3中间页面跳转时检测是否登录,以及重新登录后跳转到原来页面

        //跳转到常用联系人页面
        @RequestMapping("touristMange.html")
        private ModelAndView contactPersonManage(HttpServletRequest request) {
            ModelAndView mav=new ModelAndView("/wx/html/touristMange.html");
            Member member = super.getMember();
              if(member==null) {
                  request.getSession().setAttribute("requestPath","/wx/contacts/touristMange.html");//和跳转时请求的路径一样
                  mav = new ModelAndView("redirect:/wx/login.html");//用户登录超时时跳转到登录页面
                  return mav;
                }
            return mav;
        }
  • 相关阅读:
    solr总结
    jeesite
    Freemarker模板的使用简介
    Sd
    Sd
    Sd
    Standard Java集合类问题待整理
    Standard
    Linux并发服务器设计
    Java 生产者消费者 & 例题
  • 原文地址:https://www.cnblogs.com/guzhou-ing/p/7551767.html
Copyright © 2020-2023  润新知