ajax action交互,以及打印任意实体类jsp

function loadTableData(currentpage){
var sDate = $("#startDateSearch").val();
var eDate = $("#endDateSearch").val();
if(sDate!=''&&eDate!=''&&dateCompare(sDate,eDate)){
alertInfo("查询起始日期不能晚于终止日期");

return;
}

var requUrl="http://127.0.0.1:8080/oss/alarmAction/getAlarmList.action";
//alert(requUrl);
$.ajax({
type : 'post',
url : requUrl,
data: {//这里的参数action由于继承了acttion类,同名接收,只要有set
resourceId:$("#resourceId").val(),
alarmCount:$("#alarmCount").val(),
leavel:$("#leavel").val(),
state:$("#state").val(),
sDate:$("#startDateSearch").val(),
eDate:$("#endDateSearch").val(),
sidx:sortId,
sord:sortType,
//page:currentpage,
rows:pageSize
},
dataType : 'json',
success : function(data) {
//alert(data);
$("#listmac").text("");
var dataList =data;
//alert(dataList);
var size = data.length;
//alert(size);
var startRowNo = data.startRowNo;
var liHtml="";
for(var i=0;i<size;i++){
liHtml+='<tr>';
liHtml+='<td><span class="field">'+i+'</span></td>';
liHtml+='<td><span class="field">'+data[i].comments+'</span></td>';
liHtml+='<td><span class="field">'+data[i].triggerid+'</span></td>';
liHtml+='<td><span class="field">'+data[i].error+'</span></td>';
liHtml+='<td><span class="field">'+data[i].expression+'</span></td>';
liHtml+='<td><span class="field">'+data[i].flags+'</span></td>';
liHtml+='<td><span class="field" title="'+data[i].status+'" style="width: 400px;text-overflow: ellipsis;white-space: nowrap;display: inline-block;overflow: hidden;">'+dataList[i].id+'</span></td>';
liHtml+='<td><span class="field">'+data[i].priority+'</span></td>';
liHtml+='<td><span class="field">'+data[i].insertTime+'</span></td>';
liHtml+='</tr>';
}
$("#listmac").append(liHtml);
initCurrTablePager(data); 
}
});

}

//打印所有实体 工具BaseAction

package com.certus.action.base;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.json.annotations.JSON;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.certus.constant.Constants;
import com.certus.util.config.SessionInfo;
import com.opensymphony.xwork2.ActionSupport;

/**
* @ClassName   类  名   称:   BaseAction.java
* @Description 功能描述:       基础Action
* @author      创  建   者:   <A HREF="[email protected]">wanghao</A> 
* @date        创建日期:   2014-1-26下午3:02:59
*/
@ParentPackage("default")
public class BaseAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {

    private static final long serialVersionUID = 1L;
    private static final Logger logger = Logger.getLogger(BaseAction.class);

    protected static final String DATE_FORMAT_DEFAULT = "yyyy-MM-dd";
    protected static final String DATE_FORMAT_WITH_SECONDS = "yyyy-MM-dd HH:mm:ss";
    protected HttpServletRequest request;
    protected HttpServletResponse response;


    protected int page;
    protected int rows;
    protected String sidx;
    protected String sord;
    // 取证视频存储名称
    protected String fileStoreName;
   

    public String getFileStoreName() {
        return fileStoreName;
    }

    public void setFileStoreName(String fileStoreName) {
        this.fileStoreName = fileStoreName;
    }

    @Override
    public void setServletResponse(HttpServletResponse response) {
        this.response = response;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    @JSON
    protected int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    @JSON
    protected int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    @JSON
    protected String getSidx() {
        return sidx;
    }

    public void setSidx(String sidx) {
        this.sidx = sidx;
    }

    @JSON
    protected String getSord() {
        return sord;
    }

    public void setSord(String sord) {
        this.sord = sord;
    }

    protected void write(Object info) {
        write(info, DATE_FORMAT_DEFAULT);
    }

    protected void writePlain(String text) {
        response.setContentType("text/plain;chartset=UTF-8");
        try {
            response.getWriter().write(text);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
       
    }

    protected void write(Object info, String pattern) {
        response.setContentType("text/json;chartset=UTF-8");
        String json = "";
       
        try {
            /*if (info instanceof String) {
                json = info.toString();
            } else {*/
            json = com.alibaba.fastjson.JSON.toJSONStringWithDateFormat(info, pattern, SerializerFeature.WriteMapNullValue);
            // }
            response.getWriter().write(json);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }


}


//应用

package com.certus.oss.action;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.certus.oss.common.BeanConstants;
import com.certus.oss.service.IAlarmService;
import com.certus.oss.service.IResourceTypeService;

/**
* @ClassName   类  名   称: TemplateAction.java
* @Description 功能描述: 模板action
* @author      创  建   者: <A HREF="[email protected]">wanglz</A>
* @date        创建日期: 2015年2月6日下午5:17:56
*/
public class AlarmAction extends BaseAction {

    private static final long serialVersionUID = 1L;
//    @Resource
//    private IOperateLogService service;
    private String resourceId;
    private String alarmCount;
    private String leavel;
    private String state;
    private String sDate;
    private String eDate;

    @Resource(name = BeanConstants.ALARM_SERVICE)
private IAlarmService alarmService;
   
   
    public IAlarmService getAlarmService() {
return alarmService;
}

public void setAlarmService(IAlarmService alarmService) {
this.alarmService = alarmService;
}

public static long getSerialversionuid() {
return serialVersionUID;
}



    public String getResourceId() {
return resourceId;
}

public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

public String getAlarmCount() {
return alarmCount;
}

public void setAlarmCount(String alarmCount) {
this.alarmCount = alarmCount;
}

public String getLeavel() {
return leavel;
}

public void setLeavel(String leavel) {
this.leavel = leavel;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getsDate() {
return sDate;
}

public void setsDate(String sDate) {
this.sDate = sDate;
}

public String geteDate() {
return eDate;
}

public void seteDate(String eDate) {
this.eDate = eDate;
}

@Action(value = "/alarmAction/toIndex", results = { @Result(name = "index", type = "dispatcher", location = "/WEB-INF/jsp/view/alarm.jsp") })
    public String toTemplateIndex() {
        return "index";
    }

    @Action(value = "/alarmAction/getAlarmList")
    public void getOperateLog() {
       Map<String,String> param = new HashMap<String,String>();
       param.put("resourceId", resourceId);
       param.put("alarmCount", alarmCount);
       param.put("leavel", leavel);
       param.put("state", state);
       param.put("sDate", sDate);
       param.put("eDate", eDate);
        write(alarmService.getalarmByWebSevice(param));
    }

}



public List<AlarmType>  getalarmByWebSevice(Map<String,String> param) ;

你可能感兴趣的:(ajax action)