The reason for this garbled code is that the character set code is not specified in the page. Solution: Just specify the character set code with the following code at the beginning of the page.
& lt%@ page contenttype = "text/html; charset = utf-8 " language = " Java " % & gt;
2. The database is garbled
This kind of garbled Chinese will make the Chinese you insert into the database garbled, or garbled when reading and displaying. The solution is as follows:
Adds an encoded character set to the database connection string.
string Url = " JDBC:MySQL://localhost/digit gulf? User = root & password = root & AmpuseUnicode = true & Character encoding = GB 2312 ";
And use the following code in the page:
response . set content type(" text/html; charset = GB 23 12 ");
request . setcharacterencoding(" GB 23 12 ");
3, Chinese as a parameter to pass garbled code.
When we pass a Chinese character as a parameter to another page, garbled code will also appear. The solution is as follows:
Encode parameters when passing them, for example
RearshRes.jsp? Keywords = "+java.net.urlencoder.encode (keyword)
Then use the following statement to receive on the Receiving Parameters page.
Keywords = new string (request.getParameter("keywords ")). getBytes(" 8859 _ 1 ");
The above is the garbled problem encountered at this stage, and the core problem of garbled code is character set coding. As long as we master this point, the general problem of garbled code can be solved.