Reputation: 67
I wanted to store Indian language and again display the message saved.(CRUD operation with language message). I was able to achieve create, but when try to read i get "???" instead of language content that was saved(i.e, नमस्ते ). So When i debug i find the data till print writer object is as expected its showing in language. But when i receive in my Ajax on javascript. i get "????".
Note :
I tried content-type - text/html, application/json.
Encoding is UTF-8
At server:
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain;charset=UTF-8");
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setHeader("x-xss-protection", "1; mode=block");
response.setHeader("x-frame-options", "SAMEORIGIN");
out = response.getOutputStream();
out.write("नमस्ते");// this is coming from db
At Client
$.get({
url: "/server/langMsg",
}).then(function(rspTxt){
var json = $.parseJSON(rspTxt);
});
Upvotes: 1
Views: 56
Reputation: 67
I finally got my answer, the issue was with tomcat and mysql configuration(context.xml in my project).
Upvotes: 0
Reputation: 8806
You don't need to use ServletOutputStream
. Simply use javax.servlet.PrintWriter
,
response.getWriter().print("नमस्ते");
Upvotes: 1
Reputation: 273
I am not sure for DB, I have tried with MySQL. But, I guess should be same. if you not specified UTF8, you should see something like ?????? in ur DB else you should see the hindi data. if you not specified ,specify and try. Quick Code: First check for UTF8 compatibility with this query. If it supports you should see the output as “Character_set_system”| “UTF8” SHOW VARIABLES LIKE ‘character_set_system’;
Now that being checked, alter the table and just modify the column, specify it as UTF8
ALTER TABLE tableName MODIFY columnname VARCHAR(10) CHARACTER SET UTF8; Now, try to insert the hindi/local language value and save it. Query it and u should see the hindi text.
Upvotes: 0