Jsp parameter passing servlet receives Chinese garbled characters, jspservlet

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.