Response set the encoding.
<%@ page contenttype= "Text/html;charset=utf-8"%>
is the output encoding of the server-side Java program Runtime, which is the encoding used by the server to output HTML to the client.
<meta http-equiv= "Content-type" content= "text/html; charset=utf-8" >
Refers to what encoding the client browser displays the Web page and directs the browser to parse the incoming HTML stream on the server side. It also has a role in guiding the submission of the form to what encoding to use for incoming request.
request.setcharacterencoding ("GBK")
The page parameter is GBK encoded and passed into the server side
Similarly:
The following three methods are used to encode the output content in a servlet using the response #3# type:
1, response.setcharacterencoding ("UTF-8")
2, Response.setcontenttype ("Text/html;charset=utf-8")
Equivalent to server-side resolution: <%@ page contenttype= "Text/html;charset=utf-8"%>
3, Response.setlocale (New Java.util.Locale ("zh", "CN"))
Here's a look at the differences between the three methods:
The first method can only be used to set the encoding used in the out output stream, but he has the highest priority and can override the settings in the latter two methods;
The second method is to set the encoding of the characters in the out output stream, but also to set the browser to receive these characters in what encoding to decode, its priority is lower than the first method, but higher than the third method;
The third method can only be used to set the encoding of the characters in the out output stream, but it has the lowest priority, and after it has been coded in one of the first two methods, it is overwritten and does not work.