You noted jquery-ajax , but the JS code in your question is not recognized as jQuery. Are you really using jQuery ? This is more like a w3schools poor textbook trick.
In any case, you need to consider the character encoding in two places. On the client side, when you form-encode the parameter, you should use encodeURIComponent() . This will apply percentage coding using UTF-8.
var parameters = "content=" + encodeURIComponent(mainContent);
On the server side, until you get any parameter from the request body, you must set the request encoding in UTF-8 as follows:
request.setCharacterEncoding("UTF-8");
However, if you really use jQuery, you do not need to worry about using client side encodeURIComponent() . jQuery will handle all this for you if you use the $.post() function with a data object.
$.post('controller', { 'content': mainContent}, function() {
source share