JSP Chinese garbled problem solution Solution

zhaozj2021-02-12  167

One problem that is the most distressed problem is Chinese garbled in the process of using JSP. The following is the garbled problem I have encountered in software development and the solution.

1. The reason why JSP pages garbled this garbled is that the character set encoding should be specified in the page, the solution: As long as the following code specifies the character set coding, <% @ Page ContentType = "Text / html; charSet = GB2312 "%>

2, database catalog this garble code will make you insert into the database into garbled, or when you read the display, the solution is as follows: Add the encoded character set in the database connection string String Url = "JDBC: mysql: // ? localhost / digitgulf user = root & password = root & useUnicode = true & characterEncoding = GB2312 "; and use the following code in the page: response.setContentType (" text / html; charset = gb2312 "); request.setCharacterEncoding (" gb2312 ");

3, Chinese as a parameter transmission garbled When we deliver a Chinese characters as a parameter, there will be garbled, the solution is as follows: The parameter code is encoded when the parameter passes, such as Rearshres.jsp? Keywords = " Java .NET.URLENCODER.Encode (keywords) Then use the following statement to receive keywords = new string ("keywords"). GetBytes ("8859_1"));

The above-mentioned garbled problem, the core problem of garbled is still the problem of character set encoding, as long as this is, the general garbled problem can be resolved.

转载请注明原文地址:https://www.9cbs.com/read-7681.html

New Post(0)