web开发,登录后跳转到之前页面
2014-09-11 09:55
323 查看
点击登录,弹出对话框,触发memberlogin():
点击登录后,触发login()
//用户登录 function memberlogin(){ var href=window.location.href; if(href.indexOf("login")!=-1){ window.location.href = href; }else{ href = href.substring(href.lastIndexOf("/")+1); href = encodeURIComponent(href);//函数可把字符串作为 URI 组件进行编码。 window.location.href = "/mall/login.htm?rPath="+href;//跳转到登录页面 } return;
点击登录后,触发login()
function login(){ var loginName=$("#loginName").val(); var pwd=$("#pwd").val(); if(loginName=="登录账号" || loginName==""){ alertDialog("请输入登录账号"); return; } if(pwd=="登录密码" ||pwd==""){ alertDialog("请输入登录密码"); return; } if(pwd.indexOf(' ')>=0){ new Dialog('<div style="width:280px; height:100px;line-height:100px;text-align:center;">输入的密码有空格,请检查.</div>',{noneborder:0,beforeClose:function(){$("#pwd").focus();return true;}}).show(); return false; } $.post("/mall/checkCustomerNameAndPassword_Ajax.htm",{"accountName":loginName,"password":pwd},function(data){ if(data =="success"){ $("#loginForm").submit(); // $("form#validateSubmitForm").submit(); } else{ alertDialog("登录名或密码错误!"); } }); } //支持enter键登录 document.onkeydown = function(e){ var e = window.event ? window.event : e; if(e.keyCode == 13){ var btn=document.getElementById("btnLogin"); btn.onclick(); } }验证通过,提交表单
@RequestMapping(value = "doLogin", method = RequestMethod.POST) public String doLogin(@ModelAttribute("customer") Customer customer, BindingResult result, ModelMap modelMap, HttpSession session, Locale locale,HttpServletRequest request,HttpServletResponse response) { String accoutName = customer.getAccountName(); if (StringUtils.isBlank(accoutName)) { FieldError fieldError = new FieldError("customer", "accoutName", accoutName, true, null, null, messageSource.getMessage( "customer.accoutName.require", null, locale)); result.addError(fieldError); modelMap.put("msg", "请输入用户"); return login(customer, result, modelMap,request,session); } Customer oUser = customerService.login(accoutName, customer.getPassword()); if (oUser == null) { FieldError fieldError = new FieldError("customer", "accoutName", accoutName, true, null, null, messageSource.getMessage( "customer.accoutName.notexist", null, locale)); result.addError(fieldError); modelMap.put("msg", "用户名或密码错误"); return login(customer, result, modelMap,request,session); } if (!oUser.getPassword().equals(customer.getPassword())) { FieldError fieldError = new FieldError("customer", "password", customer.getPassword(), true, null, null, messageSource.getMessage("customer.password.error", null, locale)); result.addError(fieldError); modelMap.put("msg", "密码错误"); return login(customer, result, modelMap,request,session); } //添加本地购物车内容 String cookieCart=getCookie(WebConstants.COOKIE_CART,request); if(LogicUtils.isNotNullAndEmpty(cookieCart)){ try { String[] cookieCarts=cookieCart.split("_"); List cs=new ArrayList<Integer>(); for(int i=0;i<cookieCarts.length;i++){ String item=cookieCarts[i]; if(LogicUtils.isNotNullAndEmpty(item)){ cs.add(Integer.parseInt(item)); } } cartService.addShoppingCarts(cs, (Customer) oUser); deleteCookie(WebConstants.COOKIE_CART,response); } catch (Exception e) { log.info("用户登陆,购物车更新失败",e); } } Customer cus = customerService.findByAccountName(oUser.getAccountName()); session.setAttribute(WebConstants.LOGIN_SESSION, cus); session.removeAttribute(WebConstants.LOGIN_STATU); String rPath=(String) session.getAttribute(WebConstants.LOGIN_REDIRECT); if(LogicUtils.isNotNullAndEmpty(rPath) && !rPath.contains("logout") && !rPath.contains("register") && !rPath.contains("main.html")){ session.removeAttribute(WebConstants.LOGIN_REDIRECT); try { rPath= new String(rPath.getBytes("ISO8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage(),e); return "main"; } return "redirect:"+rPath; } return "main"; }
相关文章推荐
- web 开发,个人中心每个请求,判断用户是否登录,若没有登录,则跳转到登录页面,登录成功后返回之前页面
- 在Java Web开发中,经常会用到跳转页面的方法,一般有下面两种方法。
- 怎么实现登录之后跳转到登录之前的页面?SpringMVC+Freemarker
- ionic开发之登录状态判断,页面跳转
- jsp登录后跳转之前页面
- java web开发中,jsp使用了frameset框架,如何实现整个页面跳转,并且同一个表单中可以提交两个action
- 登录之后跳转到登录之前的页面 going to previous page after login
- 登录后跳转至之前访问页面
- iOS 开发之 点击tabbarItem添加是否跳转登录页面判断
- web开发(三)之页面跳转的问题
- JAVA安卓开发在MainActivity之前添加一个含有按钮页面跳转
- WEB开发中的页面跳转方法总结
- 黑马程序员——iOS 开发学习---登录注册页面跳转
- 怎么实现登录之后跳转到登录之前的页面?SpringMVC+Freemarker
- 1、web(html):利用VS2010开发一个跳转页面aspx
- 让Drupal在登录后自动跳转到登录之前的页面
- WEB开发中的页面跳转方法总结
- nutz_web应用中主页跳转到登录页面的方式
- iOS 开发之 点击tabbarItem添加是否跳转登录页面判断
- JavaWeb拦截器,查看用户是否登录过,未登录禁止访问页面并且跳转到登录页面