2016-10-04 140 views
2

我正在开发仅用于印地语的文本到语音网站。但是我遇到了以下问题,无法找到合适的解决方案。印地文文本显示不正确

输入:102सुरंगों (例如)

输出:(एकसौदो)_ NSWसà¥澶°à¤à¤à¥å¤

虽然数字部分被正确解释,文本被错误地处理。此外,输入改变为以下:102सà¥澶°à¤à¤à¥å¤

正确的输出必须是:(एकसौदो)_ NSWसुरंगों

这是在按钮单击时调用的index.jsp中的代码。

Preprocessor.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException, Exception { 
     response.setContentType("application/json;charset=utf-8"); 
     PrintWriter out=response.getWriter(); 

     String sent=request.getParameter("INPUT_TEXT"); 
     sent=sent.trim(); 
     NewJFrame2 njf=new NewJFrame2(); 
     String p=njf.read(sent); 

     Map m1 = new HashMap(); 
     m1.put("x", sent); 
     m1.put("y", p); 

     Gson gson = new Gson(); 
     String json = gson.toJson(m1); 
     System.out.println(json); 
     out.write(json); 
     out.close(); 
    } 

请指引我到我的错误:

function submitPreprocessForm() { 

var postData=$("#maryWebClient").serializeArray(); 

$.ajax({ 
    url: "preprocess", 
    context:this, 
    type:"POST", 
    dataType:"json", 
    data:postData, 

    success: function(response){ 
     $("#INPUT_TEXT").val(response["x"]); 
     $("#INPUT_TEXT2").val(response["y"]); 
    }, 
      error: function(errorData){alert(errorData);} 
});} 

这是模块(的一部分),使用URL模式用于显示文本预处理叫。

注意:我检查了NetBeans项目属性和web.xml中的编码。两者都被正确设置为“UTF-8”。

+1

您必须使用'request.getParameter()'方法以UTF-8格式输入。看到这个问题:[HttpServletRequest UTF-8编码](http://stackoverflow.com/questions/16527576/httpservletrequest-utf-8-encoding) – progyammer

+0

从哪里发送控制器的响应? –

+0

@progy_rock我该如何做到这一点,可以请更具体一点吗? – coder0007

回答

0

在任何getParameter()调用解决此问题之前添加request.setCharacterEncoding("UTF-8")