Spring: Controller的登录页面跳转

登录页面和登录按钮不能同时调用同一个方法,需要做跳转,否则一上来就会调用MD5密码验证,导致异常org.springframework.web.util.NestedServletException

@RequestMapping("/login")
	public String login(HttpSession session) {
		return "/sysadmin/login/login";
	}

	//点击登录按钮,页面跳转
	//登陆成功与失败分类
	@RequestMapping("/loginButton")
	public String toLogin(String userName, String password,Model model,HttpSession session) {
	
		//验证用户名和密码是否为空
		if (StringUtils.isEmpty(userName)||StringUtils.isEmpty(password)){
			model.addAttribute("errorInfo", "空了空");
			return "/sysadmin/login/login";
		}
		
		password= Md5Password.getMd5HashPassword(password, userName);
		//验证用户名和密码是否正确
		User user = userService.checkLoginByUser(userName, password);
		if (StringUtils.isEmpty(user)||user==null) {
			model.addAttribute("errorInfo", "错了错了");
			return "/sysadmin/login/login";
		}
		session.setAttribute("sessionUser", user);
		return "redirect:/home.action";
	}

你可能感兴趣的:(笔记)