Solution to the Problem of Transmitting Parameters by jsp and Receiving Chinese Garbled Codes by servlet
- 2021-11-10 10:28:37
- OfStack
I worked as an intern in the company for 8 months, All of them are made of android and h5. But what should I do if I find that I can't even serve at 1 point? So I started to learn java recently. I don't know if it is because I have learned more frames. Now it seems that springmvc framework is much simpler than before. Here I am going to learn from hibernate. After all, the data is fundamental. First of all, I used hibernate+servlet, but when the jsp page was transmitted to servlet, Chinese 1 was garbled. I tried many methods and finally solved it.
First, see the code of the project, the code of jsp page
Second, modify the server. xml file under tomcat
Third, project configuration filter
Fourth, modify the value transmission code and transmission code in servlet
request. setCharacterEncoding ("UTF-8"); //Value-by-value coding
response. setContentType ("text/html; charset=UTF-8 "); //Set the transmission code
No. 5
String username=request.getParameter("username");
String username1=new String(username.getBytes("ISO-8859-1"),"utf-8");
Ok, I used the above four kinds of failed to solve my problem, and used the fifth kind to solve it. I didn't write detailed steps here, but just said the general modification method. Everyone can use Baidu 1 to solve the detailed steps of the method, which can be solved without any accident.