无法从ExtJs控制器调用servlet

时间:2013-05-08 11:09:12

标签: javascript servlets extjs4.1 extjs-mvc

我在extjs应用程序中有一个控制器,从那里我必须调用一个servlet。但我无法从控制器调用servlet这里是我的控制器代码..... 当我运行应用程序时,总是失败部分显示“服务器端故障状态代码”这是问题所在:

Ext.define('Gamma.controller.ControlFile', {

extend : 'Ext.app.Controller',

//define the stores
stores : ['BarColumn',
  'RadarView',
  'VoiceCallStore',
  'SMSCallStore',
  'MMSCallStore',
  'GPRSUsageStore'],
//define the models 
models : ['BarCol',
  'radar',
  'VoiceCallModel',
  'SMSCallModel',
  'MMSCallModel',
  'GPRSUsageModel'],
//define the views
views : ['BarColumnChart',
  'LineChart',
  'RadarChart',
  'VoicePie',
  'SMSPie',
  'MMSPie',
  'GPRSPie'],
initializedEvents: false,
init: function() {
    this.control({
        '#barColumnChart': {
            afterlayout: this.afterChartLayout
        }
    });
},
afterChartLayout: function(){
    var me=this;
    if(this.initializedEvents==true) return;
    this.initializedEvents=true;
    Ext.getCmp('barColumnChart').series.items[0].on('itemmousedown',function(obj){

        // alert(obj.storeItem.data['source']+ ' &' + obj.storeItem.data['count']);

        var barData=obj.storeItem.data['source']+ ' &' + obj.storeItem.data['count'];

        me.dataBaseCall(obj.storeItem.data['source'],obj.storeItem.data['count']);
    });
},
dataBaseCall: function(source,count){
    //alert(barData);

    Ext.Ajax.request({
        url: "CallRatiosAnalysis",
            success: function(response, opts){
                //do what you want with the response here
                console.log("hiiiiiiiiiiii");
            },
            failure: function(response, opts) {
                alert("server-side failure with status code " + response.status);
            },
            params: {
                source: source,
                count:  count
            }

    });


    }
});

这是我的Servlet:

public class CallRatiosAnalysis extends HttpServlet {

public CallRatiosAnalysis() {
    super();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String start = request.getParameter("start");
    String limit = request.getParameter("limit");

    PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    ArrayList<IndCallType> ratios = new ArrayList<IndCallType>();
    ratios.add(new IndCallType("Voice", "40"));
    ratios.add(new IndCallType("SMS", "30"));
    ratios.add(new IndCallType("MMS", "5"));
    ratios.add(new IndCallType("GPRS", "20"));
    ratios.add(new IndCallType("Others", "5"));
    Gson gson = new Gson();
    JsonArray arrayObj = new JsonArray();
    for (int i = 0; i < ratios.size(); i++) {
        IndCallType count = ratios.get(i);
        JsonElement linObj = gson.toJsonTree(count);
        arrayObj.add(linObj);
    }

    JsonObject myObj = new JsonObject();
    myObj.addProperty("success", true);
    myObj.add("allCalls", arrayObj);
    myObj.addProperty("allCallsRatio", ratios.size());

    out.println(myObj.toString());
    out.close();
}

}

这是一个servlet,我有一些虚拟数据,并使json对象成为该数据

0 个答案:

没有答案