Instance resolution method
encodeURI (encodeURI (data))///Note two times encoded!!
$.ajax ({
Type: "Post",
Url:url,
Data:data,
ContentType: "Application/x-www-form-urlencoded;charset=utf-8",
Cache:false,
Success:viewajax.handle (this.pdomobj, This.div, URL),
Error:viewajax.error (this.pdomobj, This.div, URL)
});
Java:
string queryvalue = Java.net.urldecoder.decode ((string) request.getparameter (Querycode), "Utf-8");
Method Two
Ajax to send the request the default encoding is UTF-8, front and server coding to be unified this is not allowed to repeat, but even so, accidents still occurred;;;;;
Web effects://Note the following two times transcoding, on the server side is also carried out two times transcoding to get the normal data
$ ("#querybyname"). Click (function () {
var name = encodeURI (encodeURI ($ ("#qname"). Val ());
$.ajax ({
Type: "Post",
URL: "Querybyname.action",
ContentType: "Application/x-www-form-urlencoded;charset=utf-8",
data:{
Queryname:name
},
Success:function (msg) {
$ ("#signwork"). HTML (msg);
}
})
})
Server:struts2
string name =getqueryname ();
Name =java.net.urldecoder.decode (name, "Utf-8");
System.out.println ("action......bbbb" +name);
String Name01=java.net.urldecoder.decode (Name, "Utf-8");
System.out.println ("... cccc") ("+name01");
Here two times the transfer code to obtain the correct data, the specific reasons for the analysis;
It is said that there is another simple way to set up
Tomcat Server.xml configuration file
Uriencoding's OK.
Finally found the source of the problem, in fact, my struts2 configuration file has a little problem
This configuration information is available in the configuration file
<constant name= "struts.i18n.encoding" value= "Utf-8" ></constant>
This must be consistent with the page code, if the use of Ajax to send the request of the default Utf-8 encoding, but the background struts configuration file is GBK, let me very depressed!! Finally, the use of regular action submitted when the garbled, only to find that there is a problem. In fact, if all the use of UTF-8 encoding will not appear garbled