某APP实时登录分析项目下

来源:互联网 发布:淘宝客服外包公司注册 编辑:程序博客网 时间:2024/05/22 14:14
  1. 这一节主要介绍如何使用highmaps制作中国地图,参考地址https://www.hcharts.cn/demo/highmaps/china/grid-light
  2. 为了简化,这里把下钻的功能去掉,比较源代码和我的代码就能看见哪部分是指的下钻功能。这个地方最重要的构造返回的json数据格式,分析过程有点麻烦,这里我直接写出该结果,返回的格式应为
{"features":[{'properties':{'name':'台湾','filename':'taiwan','num':12},{'properties':{'name':'天津','filename':'tianjin','num':122},{'properties':{'name':'山西','filename':'shanxi','num':32}},{'properties':{'name':'辽宁','filename':'liaoning','num':32}},{'properties':{'name':'北京','filename':'beijing','num':52}},{'properties':{'name':'上海','filename':'shanghai','num':12}},{'properties':{'name':'江苏','filename':'jiangsu','num':132}},{'properties':{'name':'浙江','filename':'zhejiang','num':112}},{'properties':{'name':'吉林','filename':'jilin','num':62}},{'properties':{'name':'湖南','filename':'hunam','num':72}},{'properties':{'name':'江西','filename':'jiangxi','num':52}},{'properties':{'name':'安徽','filename':'anhui','num':12}},{'properties':{'name':'河北','filename':'hubei','num':12}},{'properties':{'name':'福建','filename':'fujian','num':12}},{'properties':{'name':'山东','filename':'shandong','num':12}},{'properties':{'name':'重庆','filename':'zhongqing','num':12}},{'properties':{'name':'河南','filename':'henan','num':32}},{'properties':{'name':'广东','filename':'guangdong','num':52}},{'properties':{'name':'广西','filename':'guangxi','num':12}},{'properties':{'name':'湖北','filename':'hubei','num':12}},{'properties':{'name':'青海','filename':'qinghai','num':62}},{'properties':{'name':'西藏','filename':'xicang','num':62}},{'properties':{'name':'云南','filename':'yunnan','num':82}},{'properties':{'name':'海南','filename':'hainan','num':92}},{'properties':{'name':'陕西','filename':'shanxi2','num':12}},{'properties':{'name':'贵州','filename':'guizhou','num':12}},{'properties':{'name':'香港','filename':'xianggang','num':12}},{'properties':{'name':'宁夏','filename':'ningxia','num':12}},{'properties':{'name':'新疆','filename':'xinjiang','num':12}},{'properties':{'name':'澳门','filename':'aomen','num':12}},{'properties':{'name':'黑龙江','filename':'heilongjiang','num':12}},{'properties':{'name':'四川','filename':'sichuan','num':32}},{'properties':{'name':'甘肃','filename':'gansu','num':22}},{'properties':{'name':'内蒙古','filename':'neimenggu','num':22}},{'properties':{'name':'南海诸岛','filename':'nanhai','num':12}}]}

3.分析servlet

package com.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONObject;/** * Servlet implementation class ChinaMapServlet */public class ChinaMapServlet extends HttpServlet {    private static final long serialVersionUID = 1L;    /**     * @see HttpServlet#HttpServlet()     */    public ChinaMapServlet() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request, response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub    System.out.println("post得到请求");         //得到数据         String json=DaoUtil.getMessage().toString();        response.setContentType("application/x-json");        response.setContentType("text/html;charset=utf-8");        PrintWriter print=response.getWriter();        JSONObject jsonArray = JSONObject.fromObject(json);  //转换成json数据格式        print.print(jsonArray);         print.flush();        print.close();    }}

4.工具类分析,重点在于2中数据格式的构建

public class DaoUtil {  static String sql="select * from position";  static Statement st;  static String result;  public static StringBuffer getMessage()  {       StringBuffer str=new StringBuffer("{'features':[");      try {           Connection conn=Dao.getConn();        st=conn.createStatement();        ResultSet re=(ResultSet) st.executeQuery(sql);        //re.next();        while (re.next()) {            str.append("{'properties':{'name':"+"'"+re.getString(1)+"'");            str.append(",'filename':"+"'"+re.getString(3)+"'");            str.append(",'num':"+re.getInt(2)+"}},");        }        result=str.substring(0, str.length()-1);        str.delete(0, str.length());        str.append(result);        str.append("]}");        System.out.println(str);        return str;    } catch (SQLException e) {        // TODO Auto-generated catch block        e.printStackTrace();        return null;    }  }  public static void main(String[] args) {    System.out.println(DaoUtil.getMessage().toString());}}

5.github地址https://github.com/iareuniqe/web-storm
6.备注为了让两个程序同时跑,我是把代码分成storm和展示层两部分,分别放在了两个eclipse中,同时运行的。如果有问题,可以下面留言解决。

原创粉丝点击