js文件从Struts2 Action中获取数据全过程

对应的Action类的源码:

import com.dice.voip.web.oam.base.BaseAction;
import com.dice.voip.web.oam.dao.SysInfo;
import com.dice.voip.web.oam.manager.SysInfoManager;

public class SysInfoAccountAction extends BaseAction {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8080982970228144116L;

	private List times;
	private List nums;
 	
	public String execute() throws Exception
	{
		setNums(new ArrayList());
		setTimes(new ArrayList());
		
		SysInfoManager sysInfoManager = new SysInfoManager();
		List sysinfos = sysInfoManager.getAccountNumByDay();
		
		Iterator it = sysinfos.iterator();
		while(it.hasNext()){			
			SysInfo sysInfo = it.next();
			nums.add(sysInfo.getAccountNum());
			times.add( String.valueOf(sysInfo.getTime().getMonth()) + "-" + String.valueOf(sysInfo.getTime().getDay()));
		}
		return SUCCESS;	
	}

	public List getNums() {
		return nums;
	}

	public void setNums(List nums) {
		this.nums = nums;
	}

	public List getTimes() {
		return times;
	}

	public void setTimes(List times) {
		this.times = times;
	}
 }

对应的Javascript文件源码

$(document).ready(function(){
  linechart("performance/accountinfos", "datatest");
});
 
/*
 * 曲线图
 * 参数:action:调用的action函数
 * 		 div:曲线图插入的页面
 * 	 	 title:曲线图的名称
 * 		 ytitle:曲线图y轴的名称
 *       dat: 传入数据
 */
function linechart(action,div ) {
     $.post(action, function(dat ){
         chart = new Highcharts.Chart({
            chart: {
                renderTo: div,
                defaultSeriesType: 'line',
                width: 700,
                height: 350,
                margin:[50, 30, 70, 30]
            },
            legend: {
              layout: 'vertical',
              align: 'right',
              verticalAlign: 'top',
              x: -300,
              y: 300,
            },
credits : {
                enabled:false
            },
            title: {
                text: 'DICE系统用户数量曲线图 ',
                style: {
                    margin: '10px 100px 0 0' // center it
                }
            },
            xAxis: {
                categories:dat.times ,
                labels:{
                    step:3,
                    align:'right'
                }
            },
            yAxis: {
                title: {
                    text: ''
                }
            },
            tooltip: {
                formatter: function() {
                        return ''+ this.series.name +'
'+ this.x +': '+ this.y ; } }, series: [{ name: "用户数量 ", data: dat.nums }] }); }) };

对应的JSP文件源码:


<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%>
<%@ taglib prefix="s" uri="/struts-tags"%>




  /" />
  
  性能管理--DICE系统
   
   
  


 

性能管理


你可能感兴趣的:(Struts相关基础知识)