Jsp parameter passing servlet receives Chinese garbled characters, jspservlet
After eight months of practice in the company, I have been working on android and h5 for a long time, but I found that I could not do anything even with a single service. So I recently started to learn java, I don't know if it's because the framework has learned a lot. Now it seems that springmvc is much simpler than before. Here I am going to start learning from hibernate. After all, data is fundamental, first, I used hibernate + servlet, but the Chinese characters were garbled while passing parameters to servlet on the jsp page. I tried many methods and finally solved the problem.
First, check the project code and jsp page code.
Second, modify the server. xml file under tomcat
Third, project configuration Filter
Fourth, modify the Value Transfer Encoding and Transfer Encoding in the servlet.
Request. setCharacterEncoding ("UTF-8"); // pass the value Encoding
Response. setContentType ("text/html; charset = UTF-8"); // sets the Transfer Encoding
Fifth
String username = request. getParameter ("username ");
String username1 = new String (username. getBytes ("ISO-8859-1"), "UTF-8 ");
Okay, I used the above four methods to solve my problem. I used the fifth method to solve the problem. Here I didn't write the detailed steps, but I just talked about the general modification method, you can refer to the detailed steps of Baidu's method, which can be solved without accident.