Difference Analysis of response. setContentType and response. setCharacterEncoding in JSP
- 2021-09-11 20:55:35
- OfStack
This article illustrates the difference between response. setContentType and response. setCharacterEncoding in JSP. Share it for your reference, as follows:
response.setContentType
Sets the content type of the response sent to the client, which can include character encoding description.
That is to say, if this setting is set on the server, it will play a role on the browser side, and decide the encoding method when you open the browser
If this method is called before response. getWriter () is called, the character encoding of the response will be set only from the given content type. If this method is called after response. getWriter () is called or after it is committed, the character encoding of the response will not be set. In the case of http protocol, this method sets the Content-type entity header
response. setCharacterEncoding sets the encoding of the response
If the encoding format is set on the server side using response. setContentType,
You should use the encoding format specified by response. setCharacterEncoding, which will mask the previous settings
1 It is generally recommended to set response. setCharacterEncoding
response. setContentType often fails (set but often doesn't work)
I hope this article is helpful to everyone's JSP programming.