黑马程序员技术交流社区

标题: asp.net context.Request.Form请求过的是乱码 [打印本页]

作者: 钟广雄    时间: 2012-6-7 21:43
标题: asp.net context.Request.Form请求过的是乱码
本帖最后由 钟广雄 于 2012-6-7 21:44 编辑

html  表单代码
<form method="post" action="report.ashx" target="_self">
          <table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
            <tbody>
              <tr>
                <td width="15%">网站名称:</td>
                <td width="85%"><input name="webname" maxlength="6" id="网站名称" value="" type="text">
                  网站的连接名称(不超过六个字)</td>
              </tr>
              <tr>
                <td>网站地址:</td>
                <td><input name="weburl" id="网站地址" value="http://" type="text">
                  网站链接地址</td>
              </tr>
              <tr>
                <td>收录分类:</td>
                <td><strong>
                  <input name="webtype" id="收录分类" value="" type="text">
                </strong> 依据贵站定位写明详细分类  如"音乐MP3-在线音乐"</td>
              </tr>
              <tr>
                <td>PR值:</td>
                <td><input name="webpr" id="Alexa排名" value="" type="text"></td>
              </tr>
              <tr>
                <td>联系QQ:</td>
                <td><strong>
                  <input name="qq" id="联系QQ" value="" type="text">
                </strong></td>
              </tr>
              <tr>
                <td>联系邮箱:</td>
                <td><strong>
                  <input name="email" id="联系邮箱" value="" type="text">
                </strong></td>
              </tr>
              <tr>
                <td>是否已加友链:</td>
                <td><input name="isfriend" value="1" checked="checked" type="radio">
                  是
                  <input name="isfriend" value="0" type="radio">
                  否 如未做链接将不予收录</td>
              </tr>
              <tr>
                <td></td>
                <td><label>
                 <input type=submit value="提交" />
                </label></td>
              </tr>
            </tbody>
          </table>
        </form>
HTML编码:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

ashx 代码
    web w = new web();
    database db = new database();
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        try
        {      
                w.Webname =context.Server.HtmlDecode(context.Request.Form["webname"]);
                w.Weburl = context.Request.Form["weburl"];
                w.Webtype = context.Request.Form["webtype"];
                w.Qq = Convert.ToInt32(context.Request.Form["qq"]);
                w.Email = context.Request.Form["email"];
                w.Isfriend = int.Parse(context.Request.Form["isfriend"]);
                w.Webpr = int.Parse(context.Request.Form["webpr"]);
                w.Time = DateTime.Now.ToShortTimeString();

                if (db.Entry(w) > 0)
                {
                    //context.Response.Redirect("index.html");
                    context.Response.Write("<script>alert('提交成功');history.go(-1)</script>");

                }


作者: 蒋春    时间: 2012-6-9 23:38
建议你把你网页文件的文件字符编码改成UTF-8
和在head标签中加
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
响应回去的数据默认是Utf-8的编码
作者: 朱亮辉    时间: 2012-6-10 01:08
看一下你页面的编码格式!
作者: 钟广雄    时间: 2012-6-10 09:11
朱亮辉 发表于 2012-6-10 01:08
看一下你页面的编码格式!

HTML编码:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

ashx 代码

  解决了,谢谢




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2