ModelAndView中运用RedirectView实现跳转
ModelAndView中使用RedirectView实现跳转ModelAndView默认是使用转发(forward)方式来完成请求的结果画面,
ModelAndView中使用RedirectView实现跳转
ModelAndView默认是使用转发(forward)方式来完成请求的结果画面,使用RedirectView的话,则会使用重新导向(Redirect)将请求重导到指定的结果位置。如:
- package?org.beans; ??
- ??
- import?javax.servlet.http.HttpServletRequest; ??
- import?javax.servlet.http.HttpServletResponse; ??
- ??
- import?org.springframework.web.servlet.ModelAndView; ??
- import?org.springframework.web.servlet.mvc.Controller; ??
- import?org.springframework.web.servlet.view.RedirectView; ??
- ??
- public?class?HelloController?implements?Controller?{ ??
- private?String?viewPage; ??
- ????public?ModelAndView?handleRequest(HttpServletRequest?request,?HttpServletResponse?response)?throws?Exception?{ ??
- ????????String?user=request.getParameter("user"); ??
- ????????return?new?ModelAndView(new?RedirectView(viewPage),"user",user); ??
- ????} ??
- ????public?void?setViewPage(String?viewPage)?{ ??
- ????????this.viewPage?=?viewPage; ??
- ????} ??
- ???? ??
- ?????? ??
- } ??
则运行时出现错误。该怎么改呢? 1 楼 hgq0011 2007-05-11 或许“http://www.iteye.com/topic/24675”对你有帮助。 2 楼 codeutil 2007-05-11
return new ModelAndView("redirect:"+viewPage,"user",user); 3 楼 守望者 2007-05-17 主要有以下几种:
1、 return new ModelAndView(new RedirectView(this.getViewPage()));
2、return new ModelAndView("redirect:data.html");
3、Use the new redirect: syntax in my action-servlet.xml
<property name="successView"><value>redirect:/listAuctions.html</value></property>