js怎么接收java后台持续传送过来的数据

需求是做一个局部刷新的日志一样的页面

java后台每5秒传送数据
求前后端实现的方法或者代码谢谢

用ajax定时请求,ajax有回调方法

使用websocket

ajax己是过去式了

http://blog.csdn.net/henryzhang2009/article/details/45705137

function getCpuInfo(){//与后台交互的方法
$.ajax({
url: "GetCpuAX",
type: "post",
dataType:'json',
success: function(data){

                    }
                 });
        }
        setInterval(getCpuInfo, 5000);//每五秒刷新一次

setInterval+ajax定时访问服务器
http://www.w3school.com.cn/jquery/ajax_ajax.asp

用ajax做定时请求

不用ajax用什么啊?后台代码应该要怎么写呢?

@RequestMapping(value = "/getWebInf")
public void getWebInf(HttpServletRequest request, HttpServletResponse response) throws Exception{

    String path = new TestPath().getPath();
    String returnPath = JSONObject.toJSONString(path);
    response.getWriter().write(returnPath);
}

后台我都是用这种方法,用response传给前台,持续的给前台传数据 前后台该怎么写呢?求大神帮忙啊