the difference between Response.setcontenttype and request.setcharacterencoding
Request.setcharacterencoding () is a value that sets the value taken from the request or fetched from the database
Response.setcontenttype ("TEXT/XML;CHARSET=GBK") is the set page for the Chinese encoding
The former is set dynamic text (parameters, database), the latter set the page static text
RESPONSE.SETCONTENTTYPE Specifies the encoding of the HTTP response and specifies the encoding that the browser displays.
Response.setcharacterencoding sets the encoding of the HTTP response, if the encoding format was previously set using Response.setcontenttype, Overwrites the previous setting with the encoding format specified by response.setcharacterencoding.
As with Response.setcontenttype, this method must be invoked before getwriter execution or before response is committed
Add:
Issue 1: Pass parameters from JSP page page to servlet display Chinese garbled
Solution:
If it is a POST method submission, add the following code:
Request.setcharacterencoding ("GBK");/note first to ensure that the encoding one to, the JSP page with what encoding the encoding (gbk/gb2312, etc.), this code is only valid for post submission
Response.setcontenttype ("TEXT/XML;CHARSET=GBK") is the set page for the Chinese encoding
Note: The above two lines of code must be placed in Printwriterout=response.getwriter (); Before
Get method Commit
such as variable name with
String name = new String (request.getparameter ("name"). GetBytes ("Iso-8859-1"), "GBK");
Problem 2: Resolve Get method Submit garbled problem:
Modify the Tomcat Server.xml file, plus the red part code
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443"
uriencoding= "GBK"/>
Note: The above character encoding format according to their own needs to set, as long as the consistent can
Reprint Address: http://blog.csdn.net/u012188794/article/details/41695827