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();
}
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);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。