1、javascript前端jQuery代码:
/*动态加载工厂函数*/
$(function(){
/*实时查询信息*/
realTimeQuery();
});
/*实时信息*/
function realTimeQuery(){tr= '
'
'
'
'
};
2、java后端代码:
/**
* 信息处理控制层
* @author Administrator
*
*/
@Controller
public class SyslogController {
@Resource
private SyslogService syslogService;
/**
* 实时信息展示
*/
@RequestMapping("/realTime.do")
public String realTimeQuery(Integer pageSize,HttpServletRequest request,HttpServletResponse response){
//判断是否为登录用户
String userCode = (String)request.getSession().getAttribute("userCode");
if(userCode!=null&&userCode!=""){
//实时查询
Page page = new Page(1,pageSize,pageSize,"","","","","","","","");
List
//返回数据
JSONArray jsonArray = new JSONArray();
for(Syslog syslog:list){
JSONObject jsonLog = new JSONObject();
jsonLog.put("received", syslog.getReceived());
jsonLog.put("sourceIp", syslog.getSourceIp());
jsonLog.put("sourceHostname", syslog.getSourceHostname());
jsonLog.put("facility", syslog.getFacility());
jsonLog.put("severity", syslog.getSeverity());
jsonLog.put("origin", syslog.getOrigin());
jsonLog.put("tag", syslog.getTag());
jsonLog.put("message", syslog.getMessage());
jsonArray.add(jsonLog);
}
JSONObject result = new JSONObject();
result.put("data", jsonArray);
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json" );
PrintWriter wr = response.getWriter();
wr.write(result.toString());
wr.flush();
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return "/main.jsp";
}
}
3、web.xml配置文件