在Controller中进行页面跳转的方式

方式一:返回跳转页面

 @RequestMapping(value = "/error")
    public String error(ModelMap modelMap){
        String message = "您要下载的资源已被删除!!";
        modelMap.addAttribute("message",message);
        return "error";
    }

方式二:返回ModelAndView

@RequestMapping(value = "/list")
public ModelAndView getList(HttpServletRequest request,
                         HttpServletResponse response) {
    String message = "您要下载的资源已被删除!!";
    ModelAndView model = new ModelAndView("error");
    model.addAttribute("message",message);
    return model;
    //或是
    //return new ModelAndVieW("redirect:error="+message);     
    }

方式三:使用sendRedirect函数

 @RequestMapping(value = "/downbyid")
 public void down(HttpServletRequest request,
    HttpServletResponse response, ModelMap model){
    response.sendRedirect("error");
   }

你可能感兴趣的:(java开发,Spring,MVC)