特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> JSP教程> jsp中forword和sendRedirect的区别

jsp中forword和sendRedirect的区别

时间:2009-07-03 16:54:33 作者:互联网

.R***estDispatcher.forward()


是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递.


但forward ()无法重定向至有frame的jsp文件,可以重定向至有frame的html文件,同时forward()无法在后面带参数传递,比如 servlet?name=frank,这样不行,可以程序内通过re***nse.setAttribute("name",name)来传至下一个页面.


重定向后浏览器地址栏URL不变.


例:servlet文件中重定向
CODE


public void doPost(HttpServletRequest request,HttpServletResponse response)


       throws ServletException,IOException


{


       re***nse.setContentType("text/html; charset=gb2312");


       ServletContext sc = getServletContext();


       RequestDispatcher rd = null;


       rd = sc***tRequestDispatcher("/i***x.jsp");


       rd***rward(request, response);
}

 

2.***ponse.sendRedirect()


是在用户的浏览器端工作,sendRedirect()可以带参数传递,比如servlet?name=frank传至下个页面,同时它可以重定向至不同的主机上,且在浏览器地址栏上会出现重定向页面的URL.


sendRedirect()可以重定向有frame的jsp文件.


例:servlet文件中重定向
CODE


public void doPost(HttpServletRequest request,HttpServletResponse response)


       throws ServletException,IOException


{


       re***nse.setContentType("text/html; charset=gb2312");


       re***nse.sendRedirect("/i***x.jsp");


}

相关文章 最新文章

相关应用

热门文章

猜你喜欢

返回顶部