How to handle all file encoding and garbled characters in java, php, and html _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Parse the summary of all file encoding and garbled characters in java, php, and html. Php file in garbled (such as a. php file in the browser garbled): header (Content-Type: texthtml; charsetutf-8) is set web page. Mysql_query (setnamesutf-8) sets the database. Php files are garbled (for example, php files are garbled in the browser ):
Header ("Content-Type: text/html; charset = utf-8") sets the webpage.
Mysql_query ("set names UTF-8") sets the database.

Struts in java:
Chinese garbled characters generally mean that when the request parameter has Chinese characters, the correct Chinese characters cannot be obtained in the Action. There are two methods to solve this problem in Struts2:
Set pageEncoding = "UTF-8" on the JSP page to avoid Chinese garbled characters;
If pageEncoding = "GBK" is displayed on the JSP page, modify struts. i18n. encoding = GBK and add the following statement to struts. xml to modify it.

The code is as follows:



"-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN"
Http://struts.apache.org/dtds/struts-2.0.dtd>


......


The above two methods can solve the Chinese parameters in the POST request, but the Chinese parameters in the GET request cannot be resolved. the garbled characters of the Chinese parameters in the GET request must be modified by the Tomcat server. modify the following content by adding URIEncoding = "GBK ":

Encoding (for example, a. php file garbled in the browser): header ("Content-Type: text/html; charset = utf-8") sets the webpage. Mysql_query ("set names UTF-8") sets the database ....

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.