zoukankan      html  css  js  c++  java
  • 一般处理程序学习初步——最简单的一般处理程序

    代码示例

    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;
            }
        }
    
    }
    

      

  • 相关阅读:
    win10安装nodejs,修改全局依赖位置和环境变量配置
    JavaScript判断两个对象内容是否相等
    JS判断是否是数组
    Js判断值是否是NaN
    typeof方法重写(区分数组对象)
    JS实现图片懒加载
    输入url到展示页面过程发生了什么?
    html如何在服务端跑起来
    nuxt怎么打包
    如果scss引用了字体图标文件该怎么打包
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/2828462.html
Copyright © 2011-2022 走看看