Several solutions for developing Chinese garbled characters in JAVA
I. html Garbled text or JS Garbled text introduced
1: Step 1: text file encoding
First make sure that the file's save format needs to be UTF-8, such as in eclipse, to point properties on the file, make sure that the UTF-8 is selected here
Note: In eclispe, the default js file, whose encoding is gbk, must be changed back.
2: pageEncoding
Make sure that the pageEncoding of an html or jsp file is UTF-8.
Note that the default html or jsp file created by eclipse, its pageEncoding is a iso-8859-1 and must be changed back, as shown below:
Other notes
If you forget to change pageEncoding back at first, and then enter Chinese in the file, this time text-file-encoding to UTF-8, the existing Chinese in the file will become garbled.
Ii. garbled Characters During the POST process
Assume that the POST value of webpage A is sent to webpage B. First, make sure that webpage A meets the description described in the previous section. Second, on Webpage B, perform the following operations:
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String empno = request.getParameter("empno");
3. garbled Characters During webpage URL value transfer
First, encode the URL of webpage A, such:
<A href = "delete. jsp? Ename = <% = java.net. URLEncoder. encode (rs. getObject ("ename"). toString (), "UTF-8") %> "> Delete </a>
Then, on page B, you need:
String msg = request.getParameter("ename");
String ename=new String(msg.getBytes("ISO-8859-1"),"UTF-8");