Http协议时无状态的,没有记忆功能,连接--传送--断开

一个案例验证:
MomeryTest.html
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form action="MomeryTest.ashx" method="post"> <input type="text" name="number" value="{number}" /> <input type="submit" name="btn1" /> <!--这里可以用来控制一个层的手动增长--> <input type="text" style=" width:{number}0px;border-color:blue;" /> </form> </body> </html>
MomeryTest.ashx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Web1.Day3; namespace Web1.Day4 { /// <summary> /// 实现点击数字自动增长的记忆功能!!! /// </summary> public class MomeryTest : IHttpHandler { //private int i;//该字段默认初始化时0;在这里只是做一下说明 public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; //1、引入CommonHelper这个类的命名空间 //2、读取html模板页 string html = CommonHelper.ReadHtml("~/Day4/MomeryTest.html"); //3、查看请求的报文,如果请求的报文是第一次加载的页面,, // 报文中是没有name="btn1"的,因为第一次加载的时候,你没有点击这个”提交“按钮 // 所以可以以这个特点进行数值的赋值的判断 if (string.IsNullOrEmpty(context.Request["btn1"])) { //4、页面刚加载的情况 //5、替换指定的字符串 html = html.Replace("{number}", "0"); //i = 0; } else { //i++; int num=Convert.ToInt32( context.Request["number"]); num++; //i=num; // html = html.Replace("{number}", i.ToString()); html = html.Replace("{number}", num.ToString()); } context.Response.Write(html); } public bool IsReusable { get { return false; } } } }
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号