Garbled solution request Post and Get

Garbled request post and get:

garbled request a. post.
Solution: In the beginning jsp page plus <% request.setCharacterEncoding ( "UTF-8 ");%>

                Or java code segments jsp page <% ...%> at the beginning of write request.setCharacterEncoding ( "UTF-8"); statement.

Garbled b. Get request.

Principle: We used as running Tomcat Servlet and JSP container, while the inner code is Tomcat default ISO 8859-1, so to get request mode, the data (URI) will be appended to the transmitted resource access, which is encoded Tomcat By default, if you modify the coding Tomcat, it will not get garbled for all requests, including redirection and hyperlinks. Recommendation: When using tomcat, first in server.xml, get Unicode mode (tomcat7 and earlier default encoding is iso-8859.1, after tomcat8 default is utf-8)
specific measures:

 . i: a uniform coding of each variable (not recommended)
    new new String (the old code, the new code)
 EG: name = getParameter ( "name");

        name = new String(name.getBytes("iso-8859-1"),"utf-8");

 ii: modify the port found in the server.xml Tomcat Tomcat regional profile was added URIEncoding = "utf-8" in the interior thereof.

Published 20 original articles · won praise 2 · Views 1603

Guess you like

Origin blog.csdn.net/weixin_42132733/article/details/104710500