关于重定向还有转发的一些了解,首先这篇博文是写的关于没有视图解析器的情况下怎么进行重定向和转发…
·····转发与重定向的区别
实现转发调用的是HttpServletRequest对象中的方法
实现重定向调用的是HttpServletResponse对象中的方法
转发时浏览器中的url地址不会发生改变
重定向时浏览器中的url地址会发生改变
转发时浏览器只请求一次服务器
重定向时浏览器请求两次服务器
转发能使用request带数据到跳转的页面
重定向能使用ServletContext带数据到跳转的页面
package cn.com.zzn.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**没有视图解析器的步骤*/
@Controller
public class ModelTest2 {
@RequestMapping("/m1/t2")
public String test1(Model model){
//转发forward http://localhost:8081/springmvc_04/m1/t2地址不变
model.addAttribute("msg","hello这是不需要视图解析器实现跳转的测试类");
return "redirect:/index.jsp";//重定向 http://localhost:8081/springmvc_04/index.jsp?msg=hello%地址要变
// return "forward:/WEB-INF/jsp/test.jsp";//没有视图解析器去跳转
}
}