1. What is the difference between character encodings in two places in a JSP page?
<%@ 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.
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 after the incoming server side
Similarly:
2. There are three ways 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")
相当于服务端解析:<%@ 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.
Page encoding issues involving JSPs and Servlets