difference between forward and sendredirect
Read more: http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html#ixzz2xmpb4zvh
rd.forward(request, response);
rd.forward(request, response);
Difference between SendRedirect and Forward
|
Forward()
|
SendRediret()
|
|
When we use forward method request is transfer to other resource within the same server for further processing.
|
In case of sendRedirect request is transfer to another resource to different domain or different server for futher processing.
|
|
In case of forward Web container handle all process internally and client or browser is not involved.
|
When you use SendRedirect container transfers the request to client or browser so url given inside the sendRedirect method is visible as a new request to the client.
|
|
When forward is called on requestdispatherobject we pass request and response object so our old request object is present on new resource which is going to process our request
|
In case of SendRedirect call old request and response object is lost because it’s treated as new request by the browser.
|
|
Visually we are not able to see the forwarded address, its is transparent
|
In address bar we are able to see the new redirected address it’s not transparent.
|
|
Using forward () method is faster then send redirect.
|
SendRedirect is slower because one extra round trip is required beasue completely new request is created and old request object is lost.Two browser request requird.
|
|
When we redirect using forward and we want to use same data in new resource we can use request.setAttribute () as we have request object available. (That means you can not add any url parameter in the forward, you can not changed the original url in a way. So, if you want to pass any data to the next servlet or jsp. we can use setAttribute and getAttribute. Please remember forward is in the same context.)
|
But in sendRedirect if we want to use we have to store the data in session or pass along with the URL.
|
Example of forward and SendRedirect in JSP Servlet:
Which one is good?
Read more: http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html#ixzz2xmpgi4Ie
see also: http://javarevisited.blogspot.com/2011/09/sendredirect-forward-jsp-servlet.html
difference between forward and sendredirect的更多相关文章
- jsp:forward response.sendRedirect
jsp中<jsp:forward page=""/>和response.sendRedirect("")两种跳转的区别 一.response.sen ...
- forward和sendRedirect的区别
部分内容转自:http://blog.csdn.net/zhouysh/article/details/380364和http://blog.csdn.net/frank_jay/article/de ...
- JSP的重定向有两种forward和sendRedirect
jsp:forward重定向 当index.jsp存放在tomcat服务器应用目录下时:D:\Tomcat 7.0\webapps\Spring_shizhan4ban_Chapter05\index ...
- JSP页面跳转之sendRedirect()与forward()辨析
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6044817.html 在JSP中,要实现页面的跳转,主要有两种方式实现:forward和sendRedire ...
- java 中sendredirect()和forward()方法的区别
一.文章1 HttpServletResponse.sendRedirect与RequestDispatcher.forward方法都可以实现获取相应URL资源. sendRedirect实现请求重 ...
- HttpServlet RequestDispatcher sendredirect和forward
Servlet的框架是由两个Java包组成:javax.servlet和javax.servlet.http. 在javax.servlet包中定义了所有的Servlet类都必须实现或扩展的的通用接口 ...
- Forward reference vs. forward declaration
Q:Im a bit confused. What is the difference between forward declaration and forward reference? Forwa ...
- JSP内置对象--response对象 (addCookie(),setHeader(),sendRedirect())
服务器接收客户端请求:request 服务器对客户端的回应:response javax.servlet.http的接口HttpServletResponse extends ServletRespo ...
- 浅谈forword和sendRedirect
最近项目中全部用ajax请求数据,导致在做登录过滤器时不能重定向,然后仔细翻了翻Forward和sendRedirect,以下内容收集自百度: 1. forward (服务器端作的重定向) 服务器往c ...
随机推荐
- js效果-多选只能选两项,如果超出自动取消第一次选的
这个效果很有意思,个人觉得难点在于点击选中状态的多选的数组操作,以下是代码,感谢落梨 <!DOCTYPE> <html> <head> <title> ...
- 289. Game of Life -- In-place计算游戏的下一个状态
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...
- C++ 标准库string字符串的截取
标准库的string有一个substr函数用来截取子字符串.一般使用时传入两个参数,第一个是开始的坐标(第一个字符是0),第二个是截取的长度. #include <iostream> #i ...
- MySql学习(二) —— where / having / group by / order by / limit 简单查询
注:该MySql系列博客仅为个人学习笔记. 这篇博客主要记录sql的五种子句查询语法! 一个重要的概念:将字段当做变量看,无论是条件,还是函数,或者查出来的字段. select五种子句 where 条 ...
- node.js 学习
http://www.cnblogs.com/haogj/category/612022.html
- 揭秘JavaScript中谜一样的this
揭秘JavaScript中谜一样的this 在这篇文章里我想阐明JavaScript中的this,希望对你理解this的工作机制有一些帮助.作为JavaScript程序员学习this对于你的发展有 ...
- 【代码】二进制转BCD [转]
BCD:Binary Coded Decimal 即用4位二进制编码表示1位的十进制数. 定义:BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行. ...
- 160个crackme-之Acid burn.exe
工具: Ollydbg(OD) 中文版 运行: 我们拿到一个小程序时,总要看看它到底有什么功能,或者说它阻碍了我们什么,也就是寻找突破口! 这就是程序运行后的主界面 我们进入Serial/Name后, ...
- c# 中int.ToString()的格式化的示例
格式化数值:有时,我们可能需要将数值以一定的格式来呈现,就需要对数值进行格式化.我们使用格式字符串指定格式.格式字符串采用以下形式:Axx,其中 A 为格式说明符,指定格式化类型,xx 为精度说明符, ...
- Bootstrap <基础二十二>超大屏幕(Jumbotron)
Bootstrap 支持的另一个特性,超大屏幕(Jumbotron).顾名思义该组件可以增加标题的大小,并为登陆页面内容添加更多的外边距(margin).使用超大屏幕(Jumbotron)的步骤如下: ...