轉發的時候想傳遞參數app
request.setAttribute("videoCtxPath",videoCtxPath); return "forward:"+Global.getAdminPath()+"/sites/video/videoSave.do"; 接收 String videoCtxPath=(String) request.getAttribute("videoCtxPath"); 注意,在 路徑後面傳遞參數是不能夠的,好比 return "forward:"+Global.getAdminPath()+"/sites/video/videoSave.do?id=1"; 是獲取不到id 的。
重定向:ide
/** * @author lpj * @date 2016年7月10日 */ @Controller @RequestMapping("/user") public class DemoController { @RequestMapping("/login") // public String login(@RequestParam Map<String, String> user, Model model) { public String login(@RequestParam Map<String, String> user, RedirectAttributes model) { System.out.println("用戶提交了一次表單"); String username; if (user.get("name").isEmpty()) { username = "Tom"; } else { username = user.get("name"); } model.addFlashAttribute("msg", username); // return "home";//此方式跳轉,頁面刷新會重複提交表單 return "redirect:/user/toHome"; } @RequestMapping("/toHome") public String home(@ModelAttribute("msg") String msg, Model model) { System.out.println("拿到重定向獲得的參數msg:" + msg); model.addAttribute("msg", msg); return "home"; } }
http://blog.csdn.net/u011851478/article/details/51872977.net