UTF-8 encoding is used in asp with garbled characters-garbled characters are called from the database.

Source: Internet
Author: User

 

There are many problems with UTF-8-encoded websites. I started to change CODEPAGE = "936" to CODEPAGE = "65001" and change charset = gb2312 to charset = UTF-8, but it is still garbled, as long as the script is used or garbled, the problem is finally found, that is, when the script is output, it must be output in UTF-8 encoding. Just add one sentence.

Program code

<% Response. Charset = "UTF-8" %>

Program code

First of all, of course, the page itself with UTF-8 encoding, the default encoding in DW new page as "Unicode (UTF-8 )"
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %>
② CODEPAGE = "65001" tells the server page to use UTF-8-encoded
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
③ Charset = UTF-8 tells the browser that the page uses UTF-8 Encoding
</Head>
<Body>
<% Response. Charset = "UTF-8" %>
④ The server output code is UTF-8.
</Body>
</Html>

I thought it would be okay. After refreshing the page, it would be garbled again, or when I browsed other gb2312 pages, it would be garbled again. I had to go to Google again.
Take a look at the text below, and you will know that after I add this, the top of the program

Program code

<% Session. CodePage = 65001%>

Program code

<% @ Codepage = 936%> Simplified Chinese
<% @ Codepage = 950%> traditional Chinese
<% @ Codepage = 65001%> UTF-8

Codepage specifies the encoding used by IIS to read passed strings (such as form submission and address bar transfer ).
The cause of garbled characters is that the module encoding is different when the website is to be integrated.
Do not convert the encoding of the webpage in any module to UTF-8, or GB2312 to GB2312.
So I added the following code to the conn. asp file of the GB2312 module:
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
<% Session. CodePage = 936%>
Everything is OK!
Also in the package file of the Utf-8 module (such as conn. asp, but note that conn. asp must be at the beginning of the first line of CALL) add

Program code

<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %>
<% Session. CodePage = 65001%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.