java request.forward和response.redirect 区别

1: request.getRequestDispatcher("/other/page.html?para=some").forward(ServletRequest, ServletResponse);

用于将请求在服务器端重定向至另一个页面,它会保留request里面的参数、状态等,而且客户端并不知道请求被重定向。

2: response.sendRedirect(request.getContextPath() + "/index.html");

用于告诉客户端重新发送请求至新的页面,两次请求独立,除了能在url上挂参数外,由于是两次独立请求,request和response也是独立的

猜你喜欢

转载自blog.csdn.net/YeaH_Chen/article/details/78688510
今日推荐