简体   繁体   中英

from JSON to Servlet Data

I am starting to learn JSON for my ExtJS powered UI but now I am having a problem on how to pass the data from my servlet to JSP combobox..

My servlet's output is already ok. (I hope so. :)) This is my servlet code..

JSONArray jsonarray = new JSONArray();
            ResultSetMetaData rsmd = rs.getMetaData();

            int y = 1;
            while(rs.next()){
                int numColumns = rsmd.getColumnCount();
                JSONObject obj = new JSONObject();

            for (int i=1; i<numColumns+1; i++) {
                String column_name = rsmd.getColumnName(1);
                    String column_value = rs.getString(i);
                    obj.put(column_value, y);

                }

                jsonarray.put(obj);

                 y++;
            }   

Then my combobox in ExtJS is;

            xtype: 'combo',
    name: 'genre',
    fieldLabel: 'Genre',
    mode: 'local',
    store: genres2,
    width: 120,             
    forceSelection: true,
    typeAhead: true,
    triggerAction: 'all',
    emptyText:'Select materials...',
    selectOnFocus:true,
    displayField: 'column_value'

and

var genres2 = new Ext.data.SimpleStore({
    root: 'rows',
    totalProperty: 'totalCount',
    method: 'POST',
    proxy: new Ext.data.HttpProxy({  
        url : '/ExtJS_Sample/ConnectionServlet'
    }), 

    autoLoad: true
});

genres2.load();

Hope I'm doing it right. :) Please help.

The Ext.data.SimpleStore definition should have ' fields ' property defined.

Eg.,

Ext.data.SimpleStore({
root: 'rows',
fields: [ {name: 'company'},
          {name: 'price', type: 'float'},
          {name: 'change', type: 'float'},
          {name: 'pctChange', type: 'float'}],
totalProperty: 'totalCount',
method: 'POST',
proxy: new Ext.data.HttpProxy({  
          url : '/ExtJS_Sample/ConnectionServlet'
       }), 
autoLoad: true 
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM