新闻实时分析系统 大数据Web可视化分析系统开发

1.基于业务需求的WEB系统设计

 

2.下载Tomcat并创建Web工程并配置相关服务

下载tomcat,解压并启动tomcat服务。

1)新建web app项目

 

创建好之后的效果

 

2)对tomcat进行配置

 

 

3.Web系统数据处理服务层开发

WeblogService代码开发

package com.spark.service;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.HashMap;

import java.util.Map;

 

/**

 * Created by Administrator on 2017/10/17.

 */

public class WeblogService {

    static String url ="jdbc:mysql://bigdata-pro01.kfk.com:3306/test";

    static String username="root";

    static String password="123456";

 

    public  Map queryWeblogs() {

        Connection conn = null;

        PreparedStatement pst = null;

        String[] titleNames = new String[20];

        String[] titleCounts = new String[20];

        Map retMap = new HashMap();

        try{

            Class.forName("com.mysql.jdbc.Driver");

            conn = DriverManager.getConnection(url,username,password);

            String query_sql = "select titleName,count from webCount where 1=1 order by count desc limit 20";

            pst = conn.prepareStatement(query_sql);

            ResultSet rs = pst.executeQuery();

            int i = 0;

            while (rs.next()){

                String titleName = rs.getString("titleName");

                String titleCount = rs.getString("count");

                titleNames[i] = titleName;

                titleCounts[i] = titleCount;

                ++i;

            }

            retMap.put("titleName", titleNames);

            retMap.put("titleCount", titleCounts);

        }catch(Exception e){

            e.printStackTrace();

        }

             return retMap;

    }

 

    public  String[] titleCount() {

        Connection conn = null;

        PreparedStatement pst = null;

        String[] titleSums = new String[1];

        try{

            Class.forName("com.mysql.jdbc.Driver");

            conn = DriverManager.getConnection(url,username,password);

            String query_sql = "select count(1) titleSum from webCount";

            pst = conn.prepareStatement(query_sql);

            ResultSet rs = pst.executeQuery();

            if(rs.next()){

                String titleSum = rs.getString("titleSum");

                titleSums[0] = titleSum;

            }

        }catch(Exception e){

            e.printStackTrace();

        }

        return titleSums;

    }

 

}

4.基于WebSocket协议的数据推送服务开发

WeblogSocket代码开发

package com.spark.service;

import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

 

import com.alibaba.fastjson.JSON;

 

import javax.websocket.OnClose;

import javax.websocket.OnMessage;

import javax.websocket.OnOpen;

import javax.websocket.Session;

import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/websocket")

public class WeblogSocket {

 

    WeblogService  weblogService = new WeblogService();

    @OnMessage

    public void onMessage(String message, Session session)

            throws IOException, InterruptedException {

        while(true){

            Map map = new HashMap();

            map.put("titleName", weblogService.queryWeblogs().get("titleName"));

            map.put("titleCount",weblogService.queryWeblogs().get("titleCount"));

            map.put("titleSum", weblogService.titleCount());

 

            session.getBasicRemote().

                    sendText(JSON.toJSONString(map));

            Thread.sleep(5000);

            map.clear();

        }

    }

    @OnOpen

    public void onOpen () {

        System.out.println("Client connected");

    }

    @OnClose

    public void onClose () {

        System.out.println("Connection closed");

    }

}

5.基于Echart框架的页面展示层开发

1)echart、JQuery下载

2)页面效果图选取及代码实现

 

 

6.工程编译并打包发布

参照之前将的idea打包方式,将spark web项目打包发布。

7.启动各个服务并展示最终项目运行效果

 

 

posted @ 2019-10-23 22:05  misr  阅读(663)  评论(0编辑  收藏  举报