• 一般处理程序学习初步——最简单的一般处理程序


    代码示例

    html部分代码

    <!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>
        <title>计算器</title>
    </head>
    <body>
    <form  action ="hello.ashx" method =post>
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
        <tr>
            <td>
            <input type="text" name = "txtNum1" value= "@txtNum1" />
            </td>
            <td>
            +
            </td>
            <td>
            <input type="text" name = "txtNum2" value= "@txtNum2"/>
            </td>
            <td>
            <input type="submit" value = "=">
            </td>
            <td>
            <input type="text" name = "txtSum" value= "@txtSum"/>
            </td>
        </tr>
    </table>
    <input type="hidden" name ="isPostBack" value="1"/>
    </form>
    </body>
    </html>


    aspx代码

    <%@ WebHandler Language="C#" Class="hello" %>
    
    using System;
    using System.Web;
    
    public class hello : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/html";
            //context.Response.Write("Hello World");
          
           string strPath =  context.Request.MapPath("hello.htm");
    
           string strHtml = System.IO.File.ReadAllText(strPath);
    
           
           string  strNum1 =  context.Request.Form["txtNum1"];
           string strNum2 = context.Request.Form["txtNum2"];
           int num1 = 0;
           int num2 = 0;
           int.TryParse(strNum1, out num1);
           int.TryParse(strNum2, out num2);
           int sum = num1 + num2;
           string newStrHtml = "";
           if (string.IsNullOrEmpty(context.Request.Form["isPostBack"]))
           {
               newStrHtml = strHtml.Replace("@txtNum1", "").Replace("@txtNum2", "").Replace("@txtSum", "");
           }
            else
           {
                newStrHtml = strHtml.Replace("@txtNum1", strNum1).Replace("@txtNum2", strNum2).Replace("@txtSum", sum.ToString());
               
           }
          
           context.Response.Write(newStrHtml);
    
           
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

      

  • 相关阅读:
    【书上讲解】平面上最近点对问题
    【书上讲解】快速排序
    【书上讲解】归并排序的非递归写法
    【例题 2-6】汉诺塔问题
    汉诺塔问题详解
    【例题2-5】整数的划分
    【例题2-4】排列问题
    【1-5】最大间隙问题
    【1-4】金币阵列问题
    【1-2】字典序问题
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/2828462.html
Copyright © 2020-2023  润新知