These days, I have been troubled by the problem of Chinese garbled characters. It is normal for Chinese data to be inserted into My Sql and displayed normally in the Command client line. When it is read from the database to the JSP page, it becomes "Mars".
So I searched online and saw many methods: some said to change the default-character-set=latin1 in my.ini to default-character-set=utf8, some said to change the default encoding method in Eclipse, and some said to change <%@ page contentType="text/html;charset=gb2312" %>;, and others say to change the connection character: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/MyData?user=root& ;password=3211535&useUnicode=true&characterEncoding=GB2312"); .
After several modifications, I was also confused by several modifications and several encoding methods. It was still garbled after changing it over and over. It was just that sometimes after changing a certain encoding method somewhere, it became another kind of garbled code. I worked on it until past 11 o'clock last night, but it still didn't work. I calmed down and thought, I should start from the source, so I went online to check what encoding method JSP uses to read data from My Sql. There were several opinions, so I tried them separately. . Finally succeeded, one of the sentences: <%=sqlRst.getString(1)%> was changed to <%=new String(sqlRst.getString(1).getBytes("iso8859-1"),"gb2312")%>. Convert the encoding method from iso8859-1 to gb2312 to successfully display Chinese.
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/laolik/archive/2009/12/18/5029459.aspx
-