[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。
发表人 主题:乱码问题...
嘎嘎,是我
身份:admin
发帖:1435
登陆次数:3217
1F 发表于 2011/10/21 16:28:01
使用正确的编码打开文件,再编辑。否则不对。
--------------------
解决asp+jquery+ajax中文乱码的解决方法,escape(),encodeURI...

UTF-8和GBK程序在同一Web application下切换的问题。

后来因为服务器不稳定搬到了美国,但是一放上去,我发现数据乱码了,全是????????,打开页面源文件看了下,发现只有从数据库中读取的数据是乱码的,其他的没有乱码,于是用了几种方法进行测试,终于解决了。
第一行插入 <%@ codepage="936" %>, 

链接传递参数,先要urlencode一下。

UTF-8编码时,引用的JS,css等也要另存为UTF-8编码格式。

xmlhttp返回值解码的问题。---本章集中解决各种乱码问题吧~~~~

asp用jquery输出html中文是乱码的问题---使用下jquery看看啥意思。虚拟post的编码,返回数据的解码。



asp写入中文cookie,JS读取乱码的问题。

-----------------------------------
使用google找到老外的一编文章:Display a non-US-ASCII filename in File Download dialog box
他使用如下code解决问题:
string encodefileName=ToHexString(fileName);       //使用自定义的ToHexString()方法,编码原始文件名
Response.AppendHeader("content-disposition", "attachment;filename=" + encodefileName);
        /// <summary>
        /// Encodes non-US-ASCII characters in a string.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string ToHexString(string s)
        {
            char chars = s.ToCharArray();
            StringBuilder builder = new StringBuilder();
            for (int index = 0; index < chars.Length; index++)
            {
                bool needToEncode = NeedToEncode(chars[index]);
                if (needToEncode)
                {
                    string encodedString = ToHexString(chars[index]);
                    builder.Append(encodedString);
                }
                else
                {
                    builder.Append(chars[index]);
                }
            }
            return builder.ToString();
        }
        /// <summary>
        /// Determines if the character needs to be encoded.
        /// </summary>
        /// <param name="chr"></param>
        /// <returns></returns>
        private static bool NeedToEncode(char chr)
        {
            string reservedChars = "$-_.+!*'(),@=&";
            if (chr > 127)
                return true;
            if (char.IsLetterOrDigit(chr) || reservedChars.IndexOf(chr) >= 0)
                return false;
            return true;
        }
        /// <summary>
        /// Encodes a non-US-ASCII character.
        /// </summary>
        /// <param name="chr"></param>
        /// <returns></returns>
        private static string ToHexString(char chr)
        {
            UTF8Encoding utf8 = new UTF8Encoding();
            byte encodedBytes = utf8.GetBytes(chr.ToString());
            StringBuilder builder = new StringBuilder();
            for (int index = 0; index < encodedBytes.Length; index++)
            {
                builder.AppendFormat("%{0}", Convert.ToString(encodedBytes[index], 16));
            }
            return builder.ToString();
        }
---------------------------------
sql server保存时用N(),数据库保存的是Unicode编码吧?取出时,codepage用啥都无所谓吧?

给百度、google传递搜索参数。

flash+asp xml??

asp + access,sql server

asp + mysql

asp + jquery,ajax

asp+js+cookie
--------------------------------
首先:我在本机测试的时候没有任何问题。显示,读取,存储都是完全正确的,我本机数据库的设置和远程的一样,但版本略有不同,本机版本为5.0.18-nt,远程版本为 5.0.22
我上传到远程空间后就出现了乱码问题,
以下是mysql配置
MySQL 字符集: UTF-8 Unicode (utf8)  
MySQL 连接校对: utf8_general_ci
表整理: utf8_general_ci
字段整理: utf8_general_ci

asp conn连接设置为Stmt=Set Names utf8--------------------conn字符串可以写一些数据库认识的属性吧?
asp的CODEPAGE="65001"
html页面charset=utf-8

我看过远程数据库里面的内容,也是正确的显示的
就是读出来的时候出错了,无解中,求教各位。


返回结果 源文件涉及数据库内的日文字段全是乱码

注意,网站是日文的,为了兼容中国和日本的浏览者,必须设置成utf8,不要叫我设置成gb2312。。。

终于发现为什么了...
原因我本地mysql数据库的character_set_server是GBK,而网上的数据库是 utf8
我把我本机的改成UTF8后出现相同情况。

请问接下来怎么改?
全部都是utf8了,我用phpadmin查询,表里的数据看上去也没乱码,但为什么读出来就出错呢?

我的本地数据库所有设置都是utf8的,除了character_set_server是gbk
我把character_set_server改成utf8后读出来就显示乱码了...
这个里面的数据我从后台看没有乱码啊,请问怎么让他显示不是乱码?

没有人回答吗?
现在我把原因说的简单点
就是mysql数据库my.ini里面把字符集改成gbk就可以存储日文(但我其他的字符编码全为utf8的)
如果改成utf8之后存和取都出现问题

问题暂时解决了
原因是我数据库使用的gbk编码,虽然其他的表之类的都改成utf-8了,但数据库估计还是gbk吧,比较费解
最后页面之类的utf8不变,就把Stmt=Set Names gbk就可以了
日本那边应该没问题,我想gbk设置等都是server端的。前台还是utf8的。
---------------------------------------------
在asp和.net中,越来越多的人开始使用mysql数据库。其他一些关于mysql的文章参看:
 
    http://www.aspxuexi.com/page/search.asp?query=mysql&space=0&rn=20&classid=2
 
    解决的办法:
 
    数据库字符集,表字符集,字段字符集都设为:gbk_chinese_ci
 
    注意数据库连接串里面的 Stmt=Set Names 'GBK' ,一定要有这一句。
 
    ConnectionString ="Driver={MySQL ODBC 3.51 Driver};Server=myserver;Database=mysql;User=myuser;password=mypassword;Option=3;Stmt=Set Names 'GBK'"
 
    如果使用高版本的mysql,经常出现这样的情况,中文经常为乱码;包括在php中。
 
    参考的方法:
 
    设置一下,mysql的字体.

    在mysql.ini加入
 
    [mysql] 
    default-character-set=gb2312
 
    [client] 
    default-character-set=gb2312
 
    [mysqld] 
    default-character-set=gb2312 //或gbk
 
    注册改了后,在改之前的数据库没有效果的.这些数据库目录下的db.opt文件的内容改为
 
    default-character-set=gb2312

    default-collation=gb2312_chinese_ci
----------------------------------------------
 网络上的不少文字都谈到了出现中文乱码时修改MySQL的my.ini文件中的
[mysql]default-character-set=latin1与[mysqld]default-character-set=latin1
     这两处为default-character-set=gb2312(或gbk,utf8);
     这当然没错,至少在数据库中是肯定可以显示汉字了,但是在页面中用语句查询却未必能成功,可能依然是乱码。又说在页面的页头加上
 <meta http-equiv="Content-Type" content="text/html;charset=gb2312">;
     其实这也是无关紧要的,就是加了大概不会又多少用。我也作过其他的探索,比如更改Apache服务器的字符集、重装ODBC驱动等等,所以的可能的解决办法都试了,最后才知道,也许解决问题的方法并不在此。
     其实解决ASP与MySQL数据操作中中文乱码问的关键在于数据连接,我们只需要在数据连接中加入“OPTION=3;stmt=SET NAMES GB2312”即可,但是位置与格式却非常重要;也有不少网友提到了这点,但基本都是在PHP中的编码,在ASP中的完整格式则应如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>ASP向MySQL数据库中添加数据</title>
</head>
<% 
strconnection="driver={mysql odbc 3.51 driver};database=gaorui;server=localhost;uid=root;password=luo;OPTION=3;stmt=SET NAMES GB2312"
set adodataconn = server.createobject("adodb.connection") 

插入数据时,conn也如此
-----------------------------------------
UTF-8时,发生错误时,错误页面乱码,要修改500-100.asp,呵呵

对,IIS6和IIS5的对编码的影响,可以额外提一下。IIS对UTF-8支持不是很彻底。

response.charset与meta charset的区别,说一下。

编码整体流程图,分为get和post两种方式说明。两个图。

@codepage放在第一行,因为可以提前解析它,看它的值。

IIS7乱码问题,关注一下不?

asp+oracle,关注不?

System.useCodePage=true的作用?
useCodePage 属性是来告诉 Flash Player 使用哪个代码页来解释外部数据的,当该属性设置为 false 时,Flash Player 使用 Unicode 解释外部文本文件。作为被加载的外部文件必须使用 Unicode 编码格式保存;如果加载的外部文本文件不是 Unicode 编码格式,则应将 useCodePage 设置为 true,useCodePage 的默认值是 false。-------用UTF-8最省事了,能够自动识别。该属性使用默认false就行了。

接收参数一律用iso-8859-1接收,然后再转?是否可行?是否丢字符?>127的会怎么样?
-----------------------------------------------
asp网页下载文件名是乱码----重点,没有完美方法,因为没有一个标准,每个浏览器实现的都不一样。仅IE即可。

http://www.ietf.org/rfc/rfc1867
Form-based File Upload in HTML

The content-disposition header must use US ASCII encoding. 所以需要转码

http://support.microsoft.com/kb/933133/en-us
When you try to use Internet Explorer 7 to download a file from a Web page, the file name changes
The second byte, or "trailbyte," of any of the DBCS characters contains values that represent file system-reserved characters in ASCII. For example, the "trailbyte" contains values that represent ASCII values such as 0x5c or 0x7c.

http://www.faqs.org/rfcs/rfc2231.html
RFC 2231 - MIME Parameter Value and Encoded Word Extensions: Cha

http://www.ietf.org/rfc/rfc2183.txt
The Content-Disposition Header Field



http://www.ietf.org/rfc/rfc2184.txt
MIME Parameter Value and Encoded Word Extensions:Character Sets, Languages, and Continuations



-------------------------------------------
http://www.codeproject.com/KB/aspnet/NonUSASCII.aspx

I reproduced the filename encoding and its works great (all our code is
using the Ruby language).

This DOES NOT WORK for Firefox, so I test the HTTP_USER_AGENT value and
use the word encoding described in RFC2231. I use the Base64 encoding,
not the Quoted-printable which does not work.

For these two browsers everything is perfect, I tested it with really
weird (from my point of view of course ;) ) filenames mixing french,
icelandic and korean.

As far as Opera is concerned, I have yet to find the correct way to
encode the file name. I can not imagine it is not possible, but I am
stuck on this browser. :(

-------------------------------------------
The theoretically correct syntax for use of UTF-8 in Content-Disposition is just crazy: filename*=UTF-8''foo%c3%a4 (yes, that's an asterisk, and no quotes except an empty single quote in the middle. WTF!?)

----------------------------------------------
I know this is an old post but it is still very relevant. I have found that modern browsers support rfc5987, which allows utf-8 encoding, percentage encoded (url-encoded). Then Naïve file.txt becomes:

Content-Disposition: attachment; filename*=UTF-8''Na%C3%AFve%20file.txt
Safari (5) does not supprt this and you in stead use the Safari standard of writing the file name directly in your utf-8 encoded header:

Content-Disposition: attachment; filename=Naïve file.txt
IE8 and older don't support it either and you need to use the IE standard of utf-8 encoding, percentage encoded:

Content-Disposition: attachment; filename=Na%C3%AFve%20file.txt
In ASP.Net I use the following code:

string contentDisposition;
if (Request.Browser.Browser == "IE" && (Request.Browser.Version == "7.0" || Request.Browser.Version == "8.0"))
    contentDisposition = "attachment; filename=" + Uri.EscapeDataString(fileName);
else if (Request.Browser.Browser == "Safari")
    contentDisposition = "attachment; filename=" + fileName;
else
    contentDisposition = "attachment; filename*=UTF-8''" + Uri.EscapeDataString(fileName);
Response.AddHeader("Content-Disposition", contentDisposition);
I tested the above using IE7, IE8, IE9, Chrome 13, Opera 11, FF5, Safari 5.

http://www.ietf.org/rfc/rfc5987.txt
--------------------------------------------------






嘎嘎,是我
身份:admin
发帖:1435
登陆次数:3217
2F 发表于 2011/10/27 16:34:55
get时,服务端直接
Response.Charset("GB2312")
就行了?客户端不乱码?


许多人在使用JQuery.ajax方法时肯定会遇到一个问题。在编码不是UTF-8的时候,当传递的参数里有中文的时候,服务端Request的 时候都会出现乱码。本人最近也遇到了需要传递中文参数的问题。在网上搜索一下,复制粘贴发的到处都是的“终极”“解决方案”无非就是 escape(str)来转码,然后在服务端还要写个方法再编辑一次,或用System.Text.Encoding下的方法来换来换去。
 
我很久以前一直在使用Prototype框架。在.net-GB2312或jsp-utf8下都使用过,从来没遇到有字符编码的问题。于是将Prototype和JQuery代码都下载下来打开研究原因。具体结果如下


不同之处在于JQuery默认的contentType:application/x-www-form-urlencoded
而Prototype则是contentType:application/x-www-form-urlencoded; charset=UTF-8

嘎嘎,是我
身份:admin
发帖:1435
登陆次数:3217
3F 发表于 2011/11/3 19:33:41
假使有一段a.xml文件:
<root>
<e1>xxx</e1>
<e2>xxx</e2>
<a1>xxx</a1>
<a2>xxx</a2>
</root>

如果想把<e2>和<a2>两个tag通过XQuery同时查询出来,应该怎么写?
doc('a.xml')/root/ ......
-----------------------------------
if that's all you want then:
root/node()[contains(name(),'2')]

normal form will be:
root/node()[name()='a2' or name()='e2']


I tried http://www.mizar.dk/XPath/Default.aspx..
---------------------------------------

 
标题:
消息图标:                                             
                                            
正文:



* UBB 代码开启

 
CopyRight © 心缘地方 2005-2999. All Rights Reserved