(doget) Request garbled
Introduced:
The first line in the JSP sets the encoding format
The form is located on the page using the god horse format decoding,
then the page uses the god Horse format encoding
<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>
Garbled Analysis:
The server default encoding format is set iso-8859-1 Dantin, if not set,
the browser settings encoding format is used Utf-8,
and the server decoding is used iso-8859-1, will garbled will
produce garbled
Solution:
1. Change the configuration information for the server
Path: E:\apache-tomcat-7.0.42\conf\server.xml
<connector port= "8080"
protocol= "http/1.1
" uriencoding= "UTF-8"
connectiontimeout= "20000"
redirectport= "8443"/>
plus uriencoding= "UTF-8"; ok
2. Using the inverse push method
(doPost) Request garbled
Post submission and get commit, difference:
The server decodes the time point differently, the others are the same
Get commit decoding point-in-time ====> request will decode the parameter as soon as it arrives at the server
Post commit decoding point in time =====> call to get parameter method is decoded
Solution:
Simply set the decoding table of the response before obtaining the parameter method
Case:
Request Get ()
protected void Doget (HttpServletRequest req, HttpServletResponse resp)
throws Servletexception, IOException {
System.out.println ("---------------get------------");
String name = Req.getparameter ("name");
will be garbled using Latin code iso-8859-1----------->byte
byte[] bytes = name.getbytes ("iso-8859-1");
Iso-8859-1-------------------->utf-8 Code table
String name1 = new String (bytes, "UTF-8");
System.out.println ("=========" + name1);
}
Req Post ()
Req.setcharacterencoding ("UTF-8");
String name = Req.getparameter ("name");