Solutions to Chinese garbled Characters During java post and GET Data Transmission

Source: Internet
Author: User

After N years of java Development, I have never written a website myself. Recently, I am busy with a promotional website for entrepreneurs.
I have encountered garbled characters in Chinese character sets like everyone else. In order to avoid detours, I would like to share with you a simple and practical solution.
1. POST Data Transmission
Receiving page
Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<%
Request. setCharacterEncoding ("UTF-8 ");
String zh_value = reqeust. getParameter ("zh_value ");
%>

There are two important points:
Copy codeThe Code is as follows:
PageEncoding = "UTF-8" // declare the character set for the current page

Copy codeThe Code is as follows:
Request. setCharacterEncoding ("UTF-8"); // declare the character set of the request

2. GET Data Transmission
Receiving page
Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<%
String zh_value = new String (request. getParameter ("zh_value"). getBytes ("ISO-8859-1"), "UTF-8 ")
%>

There are two important points:
Copy codeThe Code is as follows:
PageEncoding = "UTF-8" // declare the character set for the current page

Copy codeThe Code is as follows:
New String (request. getParameter ("zh_value "). getBytes ("ISO-8859-1"), "UTF-8") // decodes the obtained string into a byte array based on the ISO-8859-1 and then generates a string from the byte array based on the UTF-8

If you cannot solve the problem by using the above methods, please leave a message. I can add more methods for your reference.

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.