zoukankan      html  css  js  c++  java
  • URL传递中文:Server.UrlEncode与Server.UrlDecode

    1.设置web.config文件

    <system.web>  ......  <globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312" />  ......  </system.web> 

    2.传递中文之前,将要传递的中文参数进行编码,在接收时再进行解码。 

    >> 进行传递  string Name = "中文参数"; 

                         Response.Redirect("B.aspx?Name="+Server.UrlEncode(Name)); 

    >> 进行接收  string Name = Request.QueryString["Name"]; 

                         Response.Write(Server.UrlDecode(Name));

    3.如果是从 .HTML 文件向 .Aspx 文件进行传递中文参数的话(即不从后台用 Redirect()方法进行 Url 转换)。一样要将传递的中文参数进行编码,在接收时再进行解码。

    js中:

     escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串可以使用 unescape() 对 escape() 编码的字符串进行解码。

    >> 进行传递  <script language="JavaScript">  function GoUrl()  {  var Name = "中文参数";  location.href = "B.aspx?Name="+escape(Name);  } 

                       </script> 

                       <body onclick="GoUrl()"> 

    >> 进行接收  string Name = Request.QueryString["Name"]; 

                       Response.Write(Server.UrlDecode(Name));

    一般来说。设置web.config文件就可以了。但是如果你用 JavaScript 调用 webservice 方法的话(往webservice里面传递中文参数)。设置 web.config 文件好象无效。

    注:本文转载于:http://blog.csdn.net/ypzgq/article/details/6254025

  • 相关阅读:
    hdu 2492 树状数组 Ping pong
    HDU 1532 基础EK Drainage Ditches
    EK算法模板
    Codeforces Round #538 (Div. 2) (A-E题解)
    Codeforces Global Round 1 (A-E题解)
    Educational Codeforces Round 59 (Rated for Div. 2) DE题解
    Codeforces Round #535 (Div. 3) 题解
    Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)
    POJ2253:Frogger(改造Dijkstra)
    POJ1797:Heavy Transportation(改造Dijkstra)
  • 原文地址:https://www.cnblogs.com/GISQZC/p/5224121.html
Copyright © 2011-2022 走看看