html代码:css
table{
border-collapse:collapse; /* collapse:合并相邻的边框; separate:默认值,边框独立。*/
border-spacing:2px; /* 设置单元格间距。若是设置了合并边框,则此设置无效。 */
}
th,td{
border:1px solid green; /* 设置单元格的边框 */
padding:20px; /* 设置单元格内边距(内容到单元格的距离) */
}
用户名 | 密码 |
---|---|
$userName | $userPwd |
通常处理程序代码:
using System;
using System.Web;
using System.IO;
public class Handler : IHttpHandler {
// HttpContext 中封装了全部客户端发送的请求信息,以及服务器返回给客户端浏览器的信息。
public void ProcessRequest (HttpContext context) {
// 以文本的方式输出字符串;
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
// 设置以html模板的格式输出;
context.Response.ContentType = "text/html";
// 获取html文件的物理路径。对文件或者文件夹进行操做时,必须先获取文件的物理路径。
string filePath = context.Request.MapPath("HtmlPage.html");
// 读取html模板内容;
string strHtml = File.ReadAllText(filePath);
// 替换掉html中的占位符,返回的是替换占位符以后的html模块;
strHtml = strHtml.Replace("$userName", "张三").Replace("$userPwd", "112233");
// 将修改后的html模板输出到浏览器;
context.Response.Write(strHtml);
}
public bool IsReusable {
get {
return false;
}
}
}
若是直接在浏览器上打开html页面,效果以下,是没有替换掉占位符的状态:html
直接在浏览器上打开通常处理程序,效果以下:浏览器