0

I am using EXTJS and SERVLET, in servlet I am passing the value through request.setAttribute, But not able get the value in EXTJS.

Ext.onReady(function(){
    var myData=null;
    Ext.Ajax.request({
        url: 'DisplayTest',
        method:'POST',
        success: function ( result, request ) { 

        myData =Ext.decode(result.responseText);

        },
        failure: function ( result, request) { 
                Ext.MessageBox.alert('Failed', result.responseText); 
        } 
    });






     var store = new Ext.data.ArrayStore({
            fields: [
               {name: 'name'},
               {name: 'id'},

            ]
        });

     store.loadData(myData);

        // create the Grid
        var grid = new Ext.grid.GridPanel({
            store: store,
            columns: [
                {
                  //  id       :'company',
                    header   : 'Name', 
                    width    : 160

                },
                {
                    header   : 'ID', 
                    width    : 75 

                },


            ],

            height: 350

        });

        grid.render('db-grid');

});

In above code I want to get the value from servlet into variable myData in the form of array or List. can anyone give me some example through servlet and EXTJS.

Thanks

user980343
  • 21
  • 1
  • 4

1 Answers1

0

You will not be able to pass the data directly from Servlet using request.setAttribute. Use the formPanel.getForm().load() method to pass the request to the servlet. This method requires a JSON object in the response: something of the form:

{ success: true, {
    name: "Andy",
    dob: "11-12-1987"
    }
}

You can either send this data through the PrintWriter.write() function or use the JSON API in the servlet which directly gives the json string based on the data provided to the API.

forsvarir
  • 10,749
  • 6
  • 46
  • 77
Sunny
  • 1