redirectAttributes的用法以及相关配置
来源:互联网 发布:闹钟软件哪个好 编辑:程序博客网 时间:2024/05/23 11:46
概述:redirectAttributes是spring提供的新特性,具有页面重定向,能够向重定向的页面传递参数的功能。
应用场景:在表单提交后,可以使用此属性重定向到页面中,可以防止表单重复提交带来的不便。
下面就来为大家说说redirectAttributes的几个注意点,希望能够帮到大家:
1.这是一个使用RedirectAttributes的实例
//通过这个RedirectAttributes可以将message传递到页面中,这样就很方便优雅的解决了表单重复提交
public String shiroLogin(@RequestParam(value="username",required=false) String name,
@RequestParam(value="password", required=false) String password,
HttpSession session, RedirectAttributes attributes, Locale locale){
Subject currentUser = SecurityUtils.getSubject();
boolean flag = false;
if (!currentUser.isAuthenticated()) {
UsernamePasswordToken token = new UsernamePasswordToken(name, password);
token.setRememberMe(true);
try {
currentUser.login(token);
flag = true;
//把用户的登陆信息放到 Session 域对象中.
Object user = currentUser.getPrincipals().getPrimaryPrincipal();
System.out.println("----->" + user);
session.setAttribute("user", user);
} catch (UnknownAccountException uae) {
} catch (IncorrectCredentialsException ice) {
} catch (LockedAccountException lae) {
} catch (AuthenticationException ae) {
}
if(!flag){
attributes.addFlashAttribute("message", messageSource.getMessage("error.user.login",
null, locale));
return "redirect:/index";
}
}
return "home/success";
}
2.但是要特别注意的是,仅仅是这样简单的页面重定向是没用的,我们还需要在springmvc.xml中对要跳转的页面做映射(一定要注意,否则跳转是不成功的)
<mvc:view-controller path="/index" view-name="index"/>
- redirectAttributes的用法以及相关配置
- Spring中RedirectAttributes的用法
- Spring MVC RedirectAttributes的用法
- Spring中RedirectAttributes类的具体用法
- Spring中RedirectAttributes类的具体用法
- Spring中RedirectAttributes类的具体用法
- springmvc重定向RedirectAttributes的用法
- 关于重定向RedirectAttributes的用法
- 关于重定向RedirectAttributes的用法
- Spring MVC RedirectAttributes的用法解决办法
- springMVC RedirectAttributes用法
- springmvc之RedirectAttributes用法
- RedirectAttributes
- RedirectAttributes
- laravel-相关扩展的安装以及用法
- spring mvc RedirectAttributes 的使用
- RedirectAttributes对象addFlashAttribute()的使用
- RedirectAttributes对象addFlashAttribute()的使用
- 好听的英文网名
- 语法,句群,语篇
- Exception while invoking getStats of class ClientNamenodeProtocolTranslatorPB over 故障分析
- leetcode8
- tcp四种定时器
- redirectAttributes的用法以及相关配置
- log4j.properties 详解与配置步骤 -yellowcong
- C语言合法标识符
- 欢迎使用CSDN-markdown编辑器
- jquery源码解析之遍历同胞(上)
- CI框架中的site_url()与base_url()
- jsp学习
- Pascal 技巧
- IDL中与文件相关的函数和过程