1

我在 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();
}

}

这是我有一些虚拟数据并将 json 对象作为该数据的 servlet

4

0 回答 0