我想存储印度语言并再次显示保存的消息。(带有语言消息的 CRUD 操作)。我能够实现创建,但是尝试阅读时我得到“???” 而不是已保存的语言内容(即 नमस्ते )。因此,当我调试时,我会找到数据,直到打印编写器对象如预期的那样以语言显示。但是当我在 JavaScript 上接收我的 Ajax 时。我得到“????”。注意:我尝试了 content-type - text/html、application/json。编码为 UTF-8在服务器: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在客户$.get({ url: "/server/langMsg",}).then(function(rspTxt){ var json = $.parseJSON(rspTxt);});
3 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
我终于得到了答案,问题出在 tomcat 和 mysql 配置(我的项目中的 context.xml)。
首先 tomcat server.xml "Connection" 标签应该有 encryption="UTF-8"
在 context.xml 中的第二个,当给出 mysql 的 url 时需要附加“?useUnicode=true&characterEncoding=UTF-8”,它指定了 unicode 和编码。
白衣非少年
TA贡献1155条经验 获得超0个赞
您不需要使用ServletOutputStream
. 简单地使用javax.servlet.PrintWriter
,
response.getWriter().print("नमस्ते");
添加回答
举报
0/150
提交
取消