日期:2014-05-16 浏览次数:20349 次
Ext.onReady(function(){ var httpProxy = new Ext.data.HttpProxy({ url:'httpComboboxAction.action', listeners:{ requestcomplete:function(conn,response,options){ alert(response.responseText()); }, beforerequest:function(conn,options){ alert(111); } } }); var httpRecord = new Ext.data.Record.create([ {name:'id',type:'int',mapping:'id'}, {name:'cname',type:'string',mapping:'cname'} ]); var jsonReader = new Ext.data.JsonReader({},httpRecord); var httpStore = new Ext.data.Store({ proxy:httpProxy, reader:jsonReader }); var httpCombobox = new Ext.form.ComboBox({ store:httpStore, mode:'remote', renderTo:'httpCombobox', valueField:'id', displayField:'cname', triggerAction:'all' }); });
package org.action.extjstest; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class ComboboxAction extends ActionSupport{ public String httpDataToCombobox() throws IOException{ System.out.println("11111111"); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); // response.setCharacterEncoding("utf-8"); response.getWriter().write( "[{id:1,cname:北京},{id:2,cname:青岛},{id:3,cname:济南}]" ); return null; } }