Parsing all file encodings and garbled processing methods about java,php and HTML _php tips

Source: Internet
Author: User

PHP files in garbled (such as a.php files in the browser garbled):
Header ("Content-type:text/html;charset=utf-8") is the setting of the page.
mysql_query ("Set names Utf-8") sets the database.

Struts in Java:
Chinese garbled problem generally refers to when the request parameter has Chinese, cannot get the correct Chinese in the action. There are 2 ways to solve this problem in Struts2:
Set JSP page pageencoding= "Utf-8", will not appear in Chinese garbled;
If the JSP page pageencoding= "GBK", then you need to modify the STRUTS.I18N.ENCODING=GBK, add the following statement to the Struts.xml to modify.

Copy Code code as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache Software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>
<constant name= "struts.i18n.encoding" value= "GBK"/>
......
</struts>

The above 2 methods can resolve the Chinese parameter in post request, but the Chinese parameter in GET request cannot be solved, the garbled character of the Chinese parameter in GET request needs to be solved by modifying Tomcat's Server.xml file, modify the following content, join uriencoding= "GBK" : <connector port= "8080" ... uriencoding= "GBK"/>

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.