@slientStrom
2017-09-08T14:22:49.000000Z
字数 1565
阅读 1335
- 实例:
html #springUrl()
<link href="#springUrl('/styles/login.css')" rel="stylesheet" type="text/css"/>
图片上传测试:
public class LoginController {
private static final Logger logger=LoggerFactory.getLogger(LoginController.class);
@RequestMapping(value={"/","index.htm"})
public String index(HttpServletRequest request,ModelMap mmMap){
logger.info("index 方法");
Map<String, ?> map = RequestContextUtils.getInputFlashMap(request);
if(map!=null){
logger.info("msg is {}",map.get("msg"));
mmMap.addAttribute("msg", map.get("msg"));
}
return "index";
}
@RequestMapping(value="loginSuccess.htm")
public String login(RedirectAttributes attr,ModelMap map,HttpSession session,@RequestParam(name="loginName")String loginName
,@RequestParam(name="loginPass")String loginPass,
@RequestParam(name="vlidateCode") String vlidateCode){
ModelAndView view=new ModelAndView();
String code =(String) session.getAttribute("code");
if(!vlidateCode.equalsIgnoreCase(code)){
logger.info("{} login error",loginName);
attr.addFlashAttribute("msg", "codeError");
}else if(!"admin".equals(loginName) || !"123456".equals(loginPass)){
logger.info("the username {} password is {} logger error",loginName,loginPass);
attr.addFlashAttribute("msg", "loginError");
}else{
view.setViewName("loginSuccess");
map.addAttribute("success", "success");
return "loginSuccess";
}
return "redirect:index.htm";
}
}
代码解释:
其中:RedirectAttributes 的addFlashAttribute相当于html的post请求,将url中的传递数据隐藏。此例子中将地址栏的url重定向到index.htm.....
在controller层中重新拦截后缀为index.htm的请求。
其中:
Map<String, ?> map = RequestContextUtils.getInputFlashMap(request);将重定向传递的数据保存在map中。
利用map.get("msg")取值。