J2EE中RequestDispatcher.forward()和response.sendRedirect()的区别详谈
2013-04-24 11:25
162 查看
一、RequestDispatcher.forward()
在服务器端运行。采用采用请求转发,request对象始终存在,不会重新创建,前后页面共享同一个request。重定向后浏览器地址栏URL不变。
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html; charset=gb2312");
ServletContext sc = getServletContext();
RequestDispatcher rd = null;
rd = sc.getRequestDispatcher("/index.JSP");
rd.forward(request, response);
}
二、response.sendRedirect()
在用户的浏览器端工作。重新定向,前后页面不共享一个request。重定向后在浏览器地址栏上会出现重定向页面的URL。
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html; charset=gb2312");
response.sendRedirect("/index.JSP");
}
三、注意点
其他一些注意点参看原帖地址的博文。
原帖地址:http://www.cnblogs.com/phpzxh/archive/2010/02/01/1661137.html
在服务器端运行。采用采用请求转发,request对象始终存在,不会重新创建,前后页面共享同一个request。重定向后浏览器地址栏URL不变。
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html; charset=gb2312");
ServletContext sc = getServletContext();
RequestDispatcher rd = null;
rd = sc.getRequestDispatcher("/index.JSP");
rd.forward(request, response);
}
二、response.sendRedirect()
在用户的浏览器端工作。重新定向,前后页面不共享一个request。重定向后在浏览器地址栏上会出现重定向页面的URL。
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html; charset=gb2312");
response.sendRedirect("/index.JSP");
}
三、注意点
其他一些注意点参看原帖地址的博文。
原帖地址:http://www.cnblogs.com/phpzxh/archive/2010/02/01/1661137.html
相关文章推荐
- J2EE中RequestDispatcher.forward()和response.sendRedirect()的区别详谈
- 转 让你明白response.sendRedirect()与request.getRequestDispatcher().forward()区别
- request.getRequestDispatcher和response.sendRedirect的区别:
- response.sendRedirect(location)与rd.forward()区别
- ServletResponse接口中的sendRedirect()方法和forward()方法的区别
- response.sendRedirect()和request.getRequestDispatcher().forward(request,reponse)的区别
- HttpServletResponse.sendRedirect()与RequestDispatcher.forward()的区别
- response.sendRedirect()和request.getRequestDispatcher().forward(request,response)的区别
- response.sendRedirect()和request.getRequestDispatcher().forward(request, response)区别
- response.sendRedirect()和request.getRequestDispatcher().forward(request,response)的区别
- JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,respon 区别
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
- jsp:forward和response.sendRedirect的区别
- [Java] HttpServletResponse.sendRedirect()与RequestDispatcher.forward()的区别
- <jsp:forward>标签跳转指令和response.sendRedirect()跳转指令的区别
- 转response.sendRedirect()与request.getRequestDispatcher().forward()区别
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
- 让你明白response.sendRedirect()与request.getRequestDispatcher().forward()区别