如何通过Ajax调用返回List或ArrayList

时间:2017-11-16 13:59:44

标签: java jquery ajax struts2

我试图通过ajax调用获取动作的数据列表, 我正在编写与此问题相关的代码:

这是ajax调用代码

$.ajax({
             type : "POST",
             url : "getwonchartforValue?fromdate="+fromdate+"&todate="+todate,
             data : fromdate,
             dataType : "json",
             success : function(result) {
alert(result);
}

这里是struts.xml代码:

    <action name="getwonchartforValue" class="Actions.CrmChartAction" method="getwonchartforValue">
        <result name="success"  type="json">
        </result>
    </action>

and in action类方法是:

private List<WonDealChartDto> wonDataList;
public List<WonDealChartDto> getWonDataList() {
    return wonDataList;
}

public void setWonDataList(List<WonDealChartDto> wonDataList) {
    this.wonDataList = wonDataList;
}

public String getwonchartforValue(){


        DaoFactory dfact= new DaoFactory();
        EmailmarketingDao edao=dfact.createEmailMarketingMasterManager();
        HttpServletRequest request=ServletActionContext.getRequest();
        String fromdate=request.getParameter("fromdate");
        String todate=request.getParameter("todate");
        HttpSession session= request.getSession();

        Session hbSession=null;
        try{
            hbSession=HibernateUtilROY.getSession();
            String userid= (String)session.getAttribute("userid");
            String name= (String)session.getAttribute("name");
            String status="Won";
            wonDataList=edao.getDeatailsWonValue(fromdate, todate, userid, name, status, hbSession);




        }
        catch(Exception e){}



        return SUCCESS;
    }

我想在ajax成功中获得wonDataList(此列表中存在的数据列表)。 其中WonDealChartDto是一个bean类我在这里发布:

package dTO;

public class WonDealChartDto {


    private String noOfdeal;
    private String user;
    private String value;

    private String dealHeader;
    public String getNoOfdeal() {
        return noOfdeal;
    }
    public void setNoOfdeal(String noOfdeal) {
        this.noOfdeal = noOfdeal;
    }
    public String getUser() {
        return user;
    }
    public void setUser(String user) {
        this.user = user;
    }

    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }

    public String getDealHeader() {
        return dealHeader;
    }
    public void setDealHeader(String dealHeader) {
        this.dealHeader = dealHeader;
    }
    public WonDealChartDto() {
        super();
        // TODO Auto-generated constructor stub
    }
    public WonDealChartDto(String noOfdeal, String user, String value, String dealHeader) {
        super();
        this.noOfdeal = noOfdeal;
        this.user = user;
        this.value = value;
        this.dealHeader = dealHeader;
    }



}

我该如何解决这个问题?

0 个答案:

没有答案