Handling Chinese garbled problems in Servlets

Source: Internet
Author: User

Usually coding, often encountered some garbled problems, and now summarize the use of servlets encountered some garbled problems, simple solution two

The first simple way to handle

Data processing in Servlets is handled through request and response, and there are two ways to submit data: Post+get

①post Submission Method-As long as request.setcharacterencoding ("UTF-8") is set beforehand;-------Note: only valid for POS submission

②get Submission Method-by iso8859-1 the data sent by the client, and then into the UTF-8 type. (or other type, gbk,gb2312)

String username = Request.getparameter ("username"), username = new String (username.getbytes ("Iso8859-1", "UTF-8"));

From the above two methods can be seen if it is a get submission method, to do the processing is quite cumbersome, so in the submission mode setting, we recommend that you use post, which is one of the benefits of post. But there is also a hyperlink from the client submitted by the Chinese processing, the server can only get processing.

In response to the server, through the response response, for Chinese garbled problem, also must be processed.

through Response.setcharacterencoding ("UTF-8"); Response output in a "UTF-8" manner

Response.setcontenttype ("Text/html;charset=utf-8"); And tell the browser to open it in "UTF-8" mode.

The second filter way to deal with garbled problem, the principle and code follow up ~

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Handling Chinese garbled problems in Servlets

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.