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.