search

Home  >  Q&A  >  body text

java - 为什么过滤器只可以解决post请求的乱码问题??

PHP中文网PHP中文网2820 days ago409

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 10:37:18

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:37:18

    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");

    reply
    0
  • Cancelreply