重定向走方法跳轉(zhuǎn)及傳值:RedirectAttributes 的 addAttribute方法。
這種方式取值: request.getParameter("uname");
代碼如下:
@Controller
public class HelloAction {
@RequestMapping("/preAdd.do")
public String preAdd(RedirectAttributes attributes){
attributes.addAttribute("tag","Java1718");
return "redirect:/myhello.do";
}
@RequestMapping("/myhello.do")
public String myHello(HttpServletRequest request){
//得到重定向傳遞的值
String tag = request.getParameter("tag");
System.out.println(tag);
//跳轉(zhuǎn)到需要的頁(yè)面
// return "/WEB-INF/[前綴]hello[后綴].jsp";//完整路徑
return "hello";
}
}