jersey web service json utf-8 encoding

后端 未结 7 2008
执笔经年
执笔经年 2020-12-08 00:28

I made a small Rest webservice using Jersey 1.11. When i call the url that returns Json, there are problems with the character encoding for non english characters. The corre

7条回答
  •  醉梦人生
    2020-12-08 00:57

    i got the same issue in servlet

    kindly use : resp.setContentType("application/json;charset=utf-8");

    public static void flashOutput(HttpServletRequest req
                , HttpServletResponse resp
                , String output) {
    
            try {
    
                Utils.print2("output flash"+output);
    
                resp.setContentType("application/json;charset=utf-8");
                PrintWriter pw = resp.getWriter();
                pw.write( new String(output.getBytes("UTF-8")));
                pw.close();
                resp.flushBuffer();
    
            } catch (Exception e) {
                // TODO: handle exception
            }
    
        }// end flashOutput
    

提交回复
热议问题