页面转发与重定向

页面转发与重定向

请求转发:

- 1.服务器内部进行的转发
- 2.一次请求
- 3.地址栏不会发生变化           
//获取请求转发器
RequestDispatcher dispatcher = req.getRequestDispatcher("/myservlet04.do");
//请求转发
dispatcher.forward(req, resp);

页面重定向:

  • 重定向几次请求
    二次
  • 重定向地址栏有变化吗?
  • HttpServletRequest可以在这两次请求中共享数据吗?
    不可以
  • 那哪个域对象可以共享数据?
    context,session

实现页面重定向:

  • Location响应头
    HTTP/1.1 302
    Location: /myservlet04.do

  • 使用Servlet提供的Api
    resp.sendRedirect(“myservlet04.do”);

resp.setStatus(302);
resp.setHeader("Location", "/myservlet04.do");

//resp.sendRedirect("myservlet04.do");

js中跳转页面

window.location.href="http://localhost:8080/index.html";

ajax跳转页面

 $(window).attr("location","index.html");

猜你喜欢

转载自blog.csdn.net/m_target/article/details/82194218
今日推荐