java - Post a UTF-8 string to a servlet using jquery -


i'm trying post utf-8 string servlet (hosted in tomcat) string read on server side not utf-8. i've verified via firebug ajax header's content-type has utf-8 encoding set. i'm posting "mÉxico" server i'm receiving "mÉxico".

$.ajaxsetup({      scriptcharset: "utf-8" ,      contenttype: "application/x-www-form-urlencoded; charset=utf-8" });   $.ajax({   url: "setdata",   type: 'post',   data: 'mÉxico',   success: function(){       console.log('data set');   } }); 

here's java code in servlet

request.setcharacterencoding("utf-8"); bufferedreader reader = new bufferedreader( new inputstreamreader( request, "utf-8" ) );         char[] chr = new char[5]; reader.read( chr ); builder.append( chr ); 

update 1

i changed posting data in js encodeuricomponent('mÉxico') server still reads "mÉxico".

but, if string value of encodeuricomponent('mÉxico') i.e. 'm%c3%89xico' works! i'm zapped! idea why should work?

$.ajax({   url: "setdata",   type: 'post',   //data: 'mÉxico', ** not work   //data: encodeuricomponent('mÉxico'),  ** not work   data: 'm%c3%89xico',  //works !!!!   success: function(){       console.log('data set');   } }) 

;

i don't understand doing , kind of request parameter sending. shouldnt code that:

... data:{key:'mÉxico'}, ... 

or

... data:{key:encodeuricomponent('mÉxico')}, ... 

and in servlet

... request.getparameter('key') ... 

or

 stringurldecoder.decode(                              request.getparameter('key').tostring(),                              'utf-8'                         ); 

or didn't understand (if case sorry :/)


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -