路径:
学习springmvc ModelAndView的使用,之前一直仿别人ModelAndView的代码,都是好用的,自己建工程学了下,发现
new ModelAndView("jsp1/0724/myDialog")的时候跳转不过去
配置文件:
<property name="prefix" value="/WEB-INF/page/" />
<property name="suffix" value=".jsp" />
/** * @author sixd * 20140724 * */ @Controller public class dialogController { private static Logger logger = Logger.getLogger(dialogController.class); private DialogDao dialogDao; @Resource(name = "dialogDao") public void setDialogDao(DialogDao dialogDao) { this.dialogDao = dialogDao; } @RequestMapping(value={"/modeltest.do"}, method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView modeltest(HttpServletRequest request,HttpServletResponse response) throws IOException { ModelAndView mav = null; mav=new ModelAndView("jsp1/0724/myDialog"); //mav=new ModelAndView("0724/myDialog"); return mav; } }
调查发现,其实控制器返回的以:prefix + view name + suffix = /WEB-INF/pages/myDialog.jsp的形式
prefix:/WEB-INF/page/
suffix:.jsp
view name:myDialog
所以首先配置文件修改为:
配置文件:
<property name="prefix" value="/jsp1/" />
<property name="suffix" value=".jsp" />
控制器修改为:
/** * @author sixd * 20140724 * */ @Controller public class dialogController { private static Logger logger = Logger.getLogger(dialogController.class); private DialogDao dialogDao; @Resource(name = "dialogDao") public void setDialogDao(DialogDao dialogDao) { this.dialogDao = dialogDao; } @RequestMapping(value={"/modeltest.do"}, method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView modeltest(HttpServletRequest request,HttpServletResponse response) throws IOException { ModelAndView mav = null; //mav=new ModelAndView("jsp1/0724/myDialog"); mav=new ModelAndView("0724/myDialog"); return mav; } }
这样就可以完成跳转了。
总结:使用ModelAndView其实主要注意的是配置文件的路径设置,其次控制器对应上就可以了
本文出自 “骑猴上树” 博客,请务必保留此出处http://qihoushangshu.blog.51cto.com/7872138/1529363
ModelAndView 跳转的使用,布布扣,bubuko.com
原文地址:http://qihoushangshu.blog.51cto.com/7872138/1529363