Cliché: form Form Chinese garbage problem

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_28929579/article/details/84668179

Phenomenon: (tomcat environment + page UTF-8 + JSP UTF-8)

  1. When the form post contains Chinese background would accept a similar ç,¹ç,¹æ »'æ» 'This garbled;
  2. After the form was changed to get the problem solved;
  3. By distortion String str = new String ( "something" .getBytes ( "ISO-8859-1"), "utf-8") can be reduced to Chinese;
  4. View through the console as follows:Here Insert Picture Description

analysis:

Chinese submitted console displays no problem, the problem occurs in the server; ISO-8859-1, since decoding can be described according to ISO-8859-1 in Chinese encoding described EncodingFilter filter does not work. Then I look at the web.xml configuration is found EncodingFilter filter (filter by filter-mapping node order execution), arguably EncodingFilter filter should be the first filter, the exchange restart in XSSFilter filter, the problem is solved.

to sum up:

  1. EncodingFilter filter should be the first filter to be performed ( calling getParameter () before response.setCharacterEncoding ( "UTF-8") is provided, java coding analysis will follow all the submission, and subsequent getParameter () is not before being analyzed, so setCharacterEncoding () is invalid ).
  2. The reason why even possible to submit the get way, because the parameters get behind url then fight utf-8 to encode, when sent to the server, Tomcat URIEncoding configuration to be decoded, as follows: Here Insert Picture Description
    so EncodingFilter Filter no effect does not matter, thus causing the get crippled phenomenon.

Reference https://www.cnblogs.com/super-z/p/6230119.html

Guess you like

Origin blog.csdn.net/qq_28929579/article/details/84668179