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 ...
随机推荐
- 0525 Scrum 项目 7.0
Sprint回顾 让我们一次比一次做得更好. 1.回顾组织 主题:“我们怎样才能在下个sprint中做的更好?” 时间:设定为1至2个小时. 参与者:整个团队. 场所:能够在不受干扰的情况下讨论. ...
- BurpSuite 抓手机包
Windows and Phone 处于同一无线环境下 Windows Phone Burp Suite设置
- 关于SQLite的伪随机数
--random() 的返回值范围是:[-2^63,(2^63)-1],而通常要的是最小为 0的随机数,于是就不能直接用了,解决办法: then col else -col end) result f ...
- 尺寸不固定的图片在div中垂直居中并完全显示
前几天做一个项目,需要批量上传图片,图片外侧div尺寸固定:由于图片是用户输入的,所以大小存在不确定性,产品需求是无论图片尺寸多大,都要垂直居中完全显示 废话不多说,直接上代码 html <ul ...
- C#关于winforms窗体大小、边框、移动、动画等属性
1.窗体的边框设置为无: 2.把窗体高度调整为25,发现跑的时候总在40左右,这时需要改改属性, 把MinimumSize(0, 0)改成不为0的,最好改成和自己想要一样的大小, 最大高宽也应该这么调 ...
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(六)
前言 在接下来的篇幅里将对系统的模块功能进行编写.主要以代码实现为主.这一篇我们需要完成系统模块“角色管理”的相关功能.完成后可以对系统框架结构有进一步了解. Abstract层 之前说过,Abstr ...
- 转: Hibernate commit() 和flush() 的区别
[java] view plaincopyprint? <<精通Hibernate java对象持久化技术详解>> ,flush()方法进行清理缓存的操作,执行一系列的SQL语 ...
- 项目中常用的linux命令
1. du -sm * | sort -n 把当前目录下的文件(或目录)按大小排序,看下哪个地方占用最多: 2. pwd 获取当前目录路径 3. tail -f ...
- Newtonsoft.Json 序列化和反序列化 时间格式
From : http://www.cnblogs.com/litian/p/3870975.html 1.JSON序列化 string JsonStr= JsonConvert.SerializeO ...
- 解决远程连接mysql错误1130代码的方法
命令行登陆 mysql -uroot -p 输入密码后登陆 use mysql; select host,user from user ; grant allon *.*to root i ...