我正在使用Extjs框架。首先,我创建一个servlet以从数据库中获取数据。从数据库中获取数据后,我将存储在列表中。然后我将列表转换为json数组,现在我想使用Extjs ajax调用将这些数据放入jsp页面。我怎样才能做到这一点?
我的servlet是

String str = "select * from employee";
                    rs = stmt.executeQuery(str);
                    List<Employee> list1 = new ArrayList<Employee>();
                    while(rs.next){
                        emp = new Employee();
                        emp.setEmpId(rs.getInt(1));
                        emp.setFirstName(rs.getString(2));
                        list1.add(emp);
                    }
                    Gson gson = new Gson();
                    JsonElement element = gson.toJsonTree(list1, new TypeToken<List<Employee>>() {
                    }.getType());
                    JsonArray jsonArray = element.getAsJsonArray();
                    response.setContentType("application/json");
                    response.getWriter().print(jsonArray);


现在,通过Extjs单击按钮后,我将在jsp文件中调用此servlet。我怎么做ajax电话?我正在用这个..

    Ext.onReady(function () {
    Ext.create('Ext.Button', {
        text: 'click',
        handler: function () {
            Ext.Ajax.request({
           url: 'TestEmployee',
       success: function(result, request) {
      /////what shold I do here so that I get data here and display in jsp???
   },
   failure: function(response, opts) {
      Ext.MessageBox.alert('Failed', result.responseText);
   }
});
        },
        renderTo: Ext.getBody()

    });
    });

最佳答案

尝试

var array = Ext.decode(result.responseText);

07-24 17:47
查看更多