Yesterday, I spent more than two hours submitting JSP form data and saving it to the database with Chinese garbled characters. Today I finally solved the problem. Here are some operations to help you.
The main problem is coding. There are a lot of problems on Baidu. Some problems can be solved, and some cannot be solved using the same method. I have limited knowledge. I don't know why. Here I will only talk about my methods.
The main solution is to watch Han shunping's video. The method is as follows:
First, add an encoding class. The Code is as follows:
Public class tools {
Public static string change (string input ){
String output = "";
Try {
Output = new string (input. getbytes ("iso-8859-1"), "UTF-8 ");
} Catch (exception e ){
E. printstacktrace ();
}
Return output;
}
}
Change <% @ page contenttype = "text/html" pageencoding = "gb2312" %> to <% @ page contenttype = "text/html" pageencoding = "UTF-8" %>
For example, if I want to obtain data in a form named concernname, add this statement to concernname = tools. Change (concernname), and save the concernname to the database.
Concernname = request. getparameter ("concernname ");
Concernname = tools. Change (concernname );