zoukankan      html  css  js  c++  java
  • 重定向redirect与跳转forward区别

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoResponse.aspx.cs" Inherits="WebApplication1.DemoResponse" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="方法" />
            <br />
            <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="重定向 " />
        
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication1
    {
        public partial class DemoResponse : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                //Response为响应对象 
                Response.Write("hello!!!");
                //Response.End();//结束响应
                //Response.Write("<br>hi");
                Response.Flush(); //清除缓冲区,并将缓冲区的内容发送出去
                Response.Write("<br/>你好!!");
                Response.Clear();//清除缓冲区
                Response.Write("<br/>hi!!!");
    
            }
    
            protected void Button2_Click(object sender, EventArgs e)
            {
                //重定向
                /*forward是服务器内部重定向,程序收到请求后重新定向到另一个程序,客户机并不知道;
                redirect则是服务器收到请求后发送一个状态头给客户,客户将再请求一次,
                这里多了两次网络通信的来往。当然forward也有缺点,就是forward的页面的路径如果是相对路径就会有些问题了。
                forward后,地址栏显示的信息不改变
                而Redirect后,是开始了一个新的Http请求,因此地址栏是redirect后的地址。
                 forward保存了相关的状态信息,而redirect不保存信息。 */
                Response.Redirect("login.aspx");//告诉浏览器,让它去访问Login.aspx页
            }
        }
    }
  • 相关阅读:
    0309. Best Time to Buy and Sell Stock with Cooldown (M)
    0621. Task Scheduler (M)
    0106. Construct Binary Tree from Inorder and Postorder Traversal (M)
    0258. Add Digits (E)
    0154. Find Minimum in Rotated Sorted Array II (H)
    0797. All Paths From Source to Target (M)
    0260. Single Number III (M)
    0072. Edit Distance (H)
    0103. Binary Tree Zigzag Level Order Traversal (M)
    0312. Burst Balloons (H)
  • 原文地址:https://www.cnblogs.com/xiaz/p/5242505.html
Copyright © 2011-2022 走看看