If pages and scripts of different codes are referenced from each other, garbled characters are generated.
In Asp.net, if you want to modify the encoding of the output page, you can modify the following configuration information in Web. config:
<GlobalizationRequestencoding= "UTF-8"Responseencoding= "UTF-8" />
The above only modifies the overall default encoding. If only the encoding of a page needs to be modified, Asp.net can simply use the followingCode:
Encoding gb2312=Encoding. getencoding ("Gb2312"); Response. contentencoding=Gb2312;
In non-Asp.net applications, the data you may read is UTF-8 encoding, but to convert to gb2312 encoding, you can refer to the following code:
String Utfinfo = " Document. Write (\ "alert ('aa, are you okay ?? ');\"); " ; String Gb2312info = String . Empty; encoding utf8 = Encoding. utf8; encoding gb2312 = Encoding. getencoding ( " Gb2312 " ); // Convert the string into a byte []. Byte [] Unicodebytes = Utf8.getbytes (utfinfo ); // Perform the conversion from one encoding to the other. Byte [] Asciibytes = Encoding. Convert (utf8, gb2312, unicodebytes ); // Convert the new byte [] into a char [] and then into a string. // This is a slightly different approach to converting to revoke strate // The use of getcharcount/getchars. Char [] Asciichars = New Char [Gb2312.getcharcount (asciibytes, 0 , Asciibytes. Length)]; gb2312.getchars (asciibytes, 0 , Asciibytes. length, asciichars, 0 ); Gb2312info = New String (Asciichars );