Entering Chinese data on the JSP page and saving it to the MySQL database are garbled characters. After reading data from the database, it is still garbled on the JSP page. To solve this problem, consider the following:
1. Obtain the MySQL Character Set
The command to view the MySQL character set is:
Mysql> show variables like "character_set _ % ";
Character_set_system always UTF-8
It is best to keep these five items consistent,
Character_set_client
Character_set_connection
Character_set_database
Character_set_results
Character_set_server
2. Specify the encoding format on the JSP page to ensure that it is consistent with the MySQL character set:
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
3. Add a character encoding filter to Web. xml. The encoding method must be consistent with that of MySQL:
<! -- Famous character encoding filter --> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <filter-class> <br/> Org. springframework. web. filter. characterencodingfilter <br/> </filter-class> <br/> <init-param> <br/> <param-Name> encoding </param-Name> <br/> <param-value> UTF-8 </param-value> <br/> </init-param> <br/> </filter> </P> <p> <filter- mapping> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <URL-pattern> *. DO </url-pattern> <br/> </filter-mapping>
Note: The encoding format of the added data page and the displayed data page must be consistent. Otherwise, no garbled characters will appear in the database, and garbled characters will appear in the database.