About Ajax using the Post method submitted to the Java background garbled problem, online there are many on the server side of the set request.setcharacterencoding ("Utf-8") this method to solve or to all the back-end coding are changed to UTF-8, However, it is not possible to use this method on your own project (later analysis may be the reason for using a coded filter). After a few days groping finally buttoned up:
1. Use escape or encodeURI method when submitting Ajax. Must be used 2 times
2, the backstage Java uses the Java.net.URLDecoder class the Decode method.
Front page Local code:
/**
* Marging is a JS pair like used to host the page part functions and parameters
* XMLHTTP is a rewritten Ajax-like, attribute paramstring the parameters sent to the server for post mode
* The GBK code used in the front and back page, using the coded filter
*/
xmlhttp.paramstring= "Mname=" +marging.mnames;
Parameter passes 2 times encodeURI Code
Xmlhttp.paramstring=encodeuri (xmlhttp.paramstring);
Xmlhttp.paramstring=encodeuri (xmlhttp.paramstring);
Send Save Request
var xmlreq=xmlhttp.gettextbypost ("mailmerginged.jsp");
Background page code:
/**
* When the Request.getparameter () function is invoked, the decoding process of the URI is automatically performed
* The decoding process built into the call can cause garbled characters to appear. And after the URI is encoded two times, the Request.getparameter () function
* Obtained is the original information URI encoded once the content. Re-use the controllable decoding function Java.net.URLDecoder.decode ()
* The original correct information can be solved.
*/
String Mname=java.net.urldecoder.decode (Request.getparameter ("Mname"), "UTF-8");