1.直接指定跳转地址
public String showlistjsp(ModelMap model) { Listbeans = null; try { beans = (List ) SQLExecutor.queryList(ListBean.class, "select * from LISTBEAN"); model.addAttribute("datas", beans); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "/databind/table.jsp"; }
2.指定跳转地址别名
地址别名以path:前缀开头,别名对应的地址在mvc控制器配置文件中指定
public String showlist(ModelMap model) { Listbeans = null; try { beans = (List ) SQLExecutor.queryList(ListBean.class, "select * from LISTBEAN"); model.addAttribute("datas", beans); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } // return "/databind/table.jsp"; return "path:showlist-ok";//返回地址别名 }
在mvc控制器中配置别名path:showlist-ok对应的实际页面地址:
3.设置地址跳转的方式-forward和redirect
可以在跳转地址中指定跳转的两种模式:
forward 直接指向到目标页面,forward是默认方式,与来源请求是一个请求
redirect 重定向到目标页面,重新发出http请求
两种方式的使用示例:
redirect:
public String showlistjsp(ModelMap model) { Listbeans = null; try { beans = (List ) SQLExecutor.queryList(ListBean.class, "select * from LISTBEAN"); model.addAttribute("datas", beans); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "redirect:/databind/table.jsp"; }
forward:
public String showlistjsp(ModelMap model) { Listbeans = null; try { beans = (List ) SQLExecutor.queryList(ListBean.class, "select * from LISTBEAN"); model.addAttribute("datas", beans); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "forward:/databind/table.jsp"; }
在地址别名中设置forward和redirect
path:showlist-ok="forward:/databind/table.jsp" path:showlist-ok="redirect:/databind/table.jsp"
4.从一个地址别名跳转到其他地址别名
可以从一个地址别名跳转到其他地址别名,设置方法: