java - how to sove chinese garbled with ajax request in jquery.validate.js remote function -
example:name = 资源
rules: { name: { required: true, remote: { url: location.href.substring(0,location.href.lastindexof('/'))+"/resourcename/check/exists", datatype: "text", beforesend: function(req) { req.setrequestheader ("contenttype", "text / html; charset = uft-8"); }, type: "get" } }, url: { required: true, url: true }, menu_id: "required" }
in controller got name èµæº ,how can solve problem?
@requestmapping(value = "/resourcename/check/exists", method = requestmethod.get) public void isresourcenameexists(httpservletresponse response, @requestparam(value = "name", required = false) string name) throws ioexception { name = new string (name.getbytes("utf-8"),"utf-8"); response.setcontenttype ("text / text; charset = utf-8"); response.setcharacterencoding ("utf-8"); response.getwriter().write( string.valueof(resourceservice.findresourcesbyname(name) .isempty())); }
i solved problem name = new string(name.getbytes("iso-8859-1"),"utf-8");
Comments
Post a Comment