开发者社区> 问答> 正文

如何解决jquery中文问题

PrintWriter out = response.getWriter();
        try {    
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8"); 
            HttpSession session = request.getSession();
            User user = (User) session.getAttribute("loginUser");
            String mblogName = request.getParameter("funsName");
            HashMap<String,Object> params = new HashMap<String,Object>();
            params.put("mblogUserId", String.valueOf(user.getId()));
            StringBuffer result = new StringBuffer("");
            Map<String,Integer> areaMap = new HashMap<String,Integer>();
            List<TMBlog> blogs = MBlogHelper.getMBlogByParams(params);
            if(blogs != null && blogs.size() > 0) {
                result.append("[");
                result.append("{\"name\":\"粉丝地域分布\",");
                result.append("\"type\":\"pie\",");
//                result.append("\"xAxis\":{\"categories\":[");
//                String xAxis = "";
                for(int i = 0;i < blogs.size();i++) {
                    TMBlog blog = blogs.get(i);
                    String location = blog.getMblogUserLocation() == null ? "" : blog.getMblogUserLocation().substring(0,2);
                    if(!areaMap.containsKey(location)) {
                        areaMap.put(location, 1);
                    } else {
                        areaMap.put(location, areaMap.get(location)+1);
                    }
                     
                }
                 
//                if(areaMap != null && areaMap.size() > 0) {
//                    Iterator<String> it = areaMap.keySet().iterator();
//                    while(it.hasNext()) {
//                        String key = it.next();
//                        xAxis += "\""+key+"\",";
//                    }
//                    xAxis = xAxis.substring(0,xAxis.length()-1);
//                    result.append(xAxis+"],");
//                }
                result.append("\"data\":[");
                if(areaMap != null && areaMap.size() > 0) {
                    Iterator<String> it = areaMap.keySet().iterator();
                    while(it.hasNext()) {
                        String key = it.next();
                        Integer value = areaMap.get(key);
                        result.append("[\""+key+"\","+value+"],");
                    }
                }
                if(String.valueOf(result).endsWith(",")) {
                    result = new StringBuffer(result.substring(0, result.length()-1));
                }
                result.append("]}]");
                 
                System.out.println(response.getCharacterEncoding());
                System.out.println(response.getContentType());
                out.write(String.valueOf(result));
                out.close();
            } else {
                out.write("[{\"message\":\"no funs named "+mblogName+" no funs\"}]");
            }
        } catch (Exception e) {
            out.write(e.getMessage());
            out.close();
        }

展开
收起
a123456678 2016-07-05 15:22:40 1810 0
1 条回答
写回答
取消 提交回答
  •  HttpServletResponse response = ServletActionContext.getResponse();
                PrintWriter out = response.getWriter();
                response.setContentType("text/html; charset=UTF-8");
                String trans = java.net.URLEncoder.encode(result, "UTF-8");
                out.print(trans);
    2019-07-17 19:51:32
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
现代Javascript高级教程 立即下载
JS零基础入门教程(上册) 立即下载
23-Vue.js在前端...1506518547.pdf 立即下载