今天做登录和注册的时候出现了这个问题,百度之后说是
即提交的表单字段要与bean的类型完全对应,否则请求并不能完全对应识别。
然后改了程序里面的句子。登录和注册页面要对应起来就可以
这是登录的程序:pass+count.getSalt()原来写的是count.getUser();
@RequestMapping(value = "login", method = RequestMethod.POST) public String login(HttpServletResponse response, HttpServletRequest request, @RequestParam("user") String user, @RequestParam("pass") String pass) throws Exception { if (user != null && !user.equals("")) { Count count = countServiceImpl.selectByName(user); if (count.getUser().equals(user)) { if (MD5Util.MD5(pass + count.getSalt()).equals(count.getMd5())) { Long db = System.currentTimeMillis(); String df = db.toString(); String tokenz = user + "," + df; String token = EncryUtil.encrypt(tokenz); Cookie cookie = new Cookie("name", token); //cookie.setDomain("www.hanyaohe.top"); cookie.setPath("/"); cookie.setMaxAge(1000 * 60 * 60); response.addCookie(cookie); return "redirect:/u/one"; } } } return "redirect:/login"; }
而注册的逻辑写的是:
@RequestMapping(value = "register",method = RequestMethod.POST) public String register(@RequestParam("user") String user,@RequestParam("pass") String pass,@RequestParam("online") String online,@RequestParam("workers") String workers) throws Exception{ int check = countServiceImpl.countByName(user); if(check>0){ return "register"; } else { String salt = UUIDUtil.getUUID(); String MD5 = MD5Util.MD5(pass+salt); Count count = new Count(); count.setPass(pass); count.setOnline(online); count.setWorkers(user); count.setSalt(salt); count.setUser(user); count.setMd5(MD5); countServiceImpl.insert(count); return "login"; }MD5(是pass+salt),要对应才行。
x