Servlet garbled characters, servlet Chinese garbled characters

Source: Internet
Author: User

Servlet garbled characters, servlet Chinese garbled characters

Garbled Post: request. setCharacterEncoding ("UTF-8 ");

 

GET method:

1. Modify the tomcat decoding Character Set conf/server. xml URIEndoing = "UTF-8"

2. Manually recode

Username = URLEncoder. encode (username, "ISO-8859-1 ");

Username = URLDecoder. decode (username, "UTF-8 ");

Simplified:

Username = new String (username. getBytes ("ISO-8859-1"), "UTF-8 ");


Servlet Chinese garbled characters

Can you enter Chinese characters for your ID attribute? If yes, you need to set the character encoding before receiving the parameter, request. setCharacterEncoding ("gbk");, there is a response. setContentType ("text/html; charset = gbk"); in this way, do not use this sentence during development: response. setCharacterEncoding ("UTF-8 ");

Servlet Chinese garbled characters

The garbled problem is complicated, and there are many reasons! First, String name = request. getParameter ("name"); the obtained name is garbled if it is data submitted in a non-utf8 encoding method, if the encoding method specified by the page file ContentType attribute is UTF-8, the encoding method of this file must be UTF-8 or garbled. Many times we find that the encoding method of both the server and page files is UTF-8, however, it is garbled. Most of the problem is that the file encoding method is not caused by UTF-8, so you can check the page file encoding method and use EditPlus and other tools to modify the file encoding method, the encoding method specified in ContentType will tell the browser what encoding is used for parsing. If the page file is compiled by GBK, but the content type is set to UTF-8, it will be garbled!
There is a wider range of UTF-8 than GBK, said does not support Chinese broken talk!
The code above does not specifically reflect the cause of Garbled text! Garbled characters may be caused by server files, page files, and the encoding environment of servers and clients.

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.