`

response.redirect 与javascript 的 location.href 的区别

    博客分类:
  • jsp
 
阅读更多
response.redirect是请求转向,location.href 是浏览器转向.
 1、Response.Redirect():
Response.Redirect方法导致浏览器链接到一个指定的URL。
当Response.Redirect()方法被调用时,它会创建一个应答,
应答头中指出了状态代码302(表示目标已经改变)以及新的目标URL。
浏览器从服务器收到该应答,利用应答头中的信息发出一个对新URL的请求。
这就是说,使用Response.Redirect方法时重定向操作发生在客户端,总共涉及到两次与服务器的通信(两个来回):
第一次是对原始页面的请求,得到一个302应答,
第二次是请求302应答中声明的新页面,得到重定向之后的页面。
  
如果你请求含有response.redirect的页面时,在服务器端已经给你转向了,服务器遇到该语句时直接转向目的页面.
 而location.href一般是浏览器遇到该语句时,重新向另一个地址进行请求,可见,response.redirect只是一次请求,而客户端使用location转向时要两次向服务器进行请求.
 因为服务器端是不存在window等浏览器窗口的,所以location绝对不会是服务端代码,只能在客户端输出.
事实上,如果在客户端中,js语句中同样也存在redirect语句,这时两者的作用一样.
但机理不同,redirect只是一个转向语句,遇到该语句时,直接转向,客户端是两次请求的.
而location相当于你在地址栏中输入了地址后按回车! 如果对转向没有控制的话,两者在客户端是一样的.
但response.redirect往往用于服务端,而location只能用在客户端!
分享到:
评论

相关推荐

    在线考试系统设计与实现

    基于C#的在线考试系统设计与实现的文档 (4)单击“注册”按钮,进入注册页面。 //用户注册 protected void btnZhunce_Click(object sender, EventArgs e) { //Page.Response.Redirect("zhuce.aspx"); Response....

    asp.net 常用页面刷新

    第一: C# codeprivate void Button1_Click( object sender, System.EventArgs e ) { ...Response.Write( " < script language=javascript>window.location.href=document.URL; < /script>" ); }

    asp连接数据库代码实例

    location.href(\'index.asp\');</script>\" end if %> -------------------------------------- 3.显示记录 set rs=server.createobject(\"adodb.recordset\") sql=\"select * from biao order by id desc...

    fso浏览54646465465464564

    Response.Write "<tr value="""&oDrive.DriveLetter&":\"" ondblclick=""location.href='?page=fso&fname='+escape(this.value);""" If Islight Then Response.Write " bgcolor='#EEEEEE'" Response.Write ">...

    js 有框架页面跳转(target)三种情况下的应用

    jsp: 代码如下: [removed] window.parent.frames.location.href=”../welcome.en” [removed] java: 代码如下: PrintWriter out = response.getWriter(); out.write(“[removed]window.parent.frames.location.href...

    如何实现web页面的提示保存功能

    javascript:return checksave(this.href)" href=DownloadFiles1DownloadFiles1DownloadFiles1"TestNoNeedCheck.aspx">sohu</a><BR> ;javascript:return checksave(this.href)" href=Download...

    ASP.NET程序中常用的三十三种代码.txt

     e.item.Attributes.Add("ondblclick", "location.href=’../ShippedGrid.aspx?id=" + OrderItemID + "’"); }  双击表格打开新一页 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ...

    网上图书销售数据库+ASP

    '-------------------------------------------------------------------- ' Microsoft ADO ' ...' ' ' ' ADO constants include file for VBScript ' '------------------------------------------------------------...

    ASP.NET常用代码

    e.item.Attributes.Add("ondblclick", "location.href='../ShippedGrid.aspx?id=" + OrderItemID + "'"); } 双击表格打开新一页 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType....

    网页跳转代码大全

    Response Redirect www admin5 com Response End 如果你要在客户端跳转 可以这样: <script language "javascript" type "text javascript"> window location "...

    php.ini-development

    You can redirect all of the output of your scripts to a function. For ; example, if you set output_handler to "mb_output_handler", character ; encoding will be transparently converted to the ...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    目标是创建没有JavaScript,没有CSS,没有UpdatePanel,没有WebServices的Web应用程序。 支持的浏览器: IE 7.0+, Firefox 3.0+, Chrome 2.0+, Opera 9.5+, Safari 3.0+ 注:ExtAspNet基于一些开源的程序ExtJS, ...

    ExtAspNet_v2.3.2_dll

    目标是创建没有ViewState,没有JavaScript,没有CSS,没有UpdatePanel,没有WebServices的Web应用程序。 支持的浏览器: IE 7.0+, Firefox 3.0+, Chrome 2.0+, Opera 9.5+, Safari 3.0+ 注:ExtAspNet基于一些开源...

    教师档案管理系统源代码

    response.redirect "admin_xxcx.asp" end if if typeid="" then sqlstudent="select * from student where name like '%"&keyword&"%' order by adid desc" end if if typeid="1" then ...

Global site tag (gtag.js) - Google Analytics