java - 为什么过滤器只可以解决post请求的乱码问题??
PHP中文网
PHP中文网 2017-04-18 10:35:18
0
2
371
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
巴扎黑

It’s not just a matter of post编码,而是characterEncoding只对body有效。
http有很多method比如像put方法也是有body的。
即使你使用post如果url中存在中文query parameters一样需要针对urlsetting the encoding.

洪涛

1. Because few people use the GET method to transmit Chinese content. As for why the filter only solves the problem of Chinese transmission garbled characters in the POST method, I think it is not a technical problem. It may be intentional by the designer, hoping to guide us to use the POST method more. It's like requiring a large truck to carry a lot of people like a passenger car. For the person who designs the large truck, he won't take this situation into consideration.

2. The problem of transmitting Chinese garbled characters in the GET method is not unsolvable. The solution is also very simple, but it is not recommended because this method is not universal for the POST method. The sample code is as follows:

String username = request.getParameter("username");
username = new String(username.getBytes( "iso-8859-1" ), "utf-8");
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!