Note: To use extjs, you must introduce the corresponding package to the page.
<LINK rel = "stylesheet" type = "text/CSS" href = "../EXT/resources/CSS/ext-all.css"/>
<SCRIPT type = "text/JavaScript" src = "../EXT/adapter/EXT/ext-base.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../EXT/ext-all.js"> </SCRIPT>
JS
Ext. onready (function () {name = encodeuri (name); // page transcoding, to prevent garbled background decoding var OBJ = document. getelementbyid ("div1"); If (OBJ! = NULL) {var divinnerhtml = obj. innerhtml; If (divinnerhtml! = NULL & divinnerhtml. trim (). length> 0) {document. getelementbyid ("div1 "). innerhtml = "" ;};}; var store = new Ext. data. store ({// method: 'post', URL: "mapinfos? Areaname = "+ name +" ", // request URL path, and the reader: New Ext. data. xmlreader ({record: "item"}, // note that this item is the row of data ["ziduan0", "ziduan1", "ziduan2", "ziduan3"])}); // var Colm = new Ext. grid. columnmodel ([{header: "field 0", dataindex: "ziduan0" },{ header: "Field 1", dataindex: "ziduan1", width: 80 },{ header: "Field 2", dataindex: "ziduan2", width: 50}, {header: "Field 3", dataindex: "ziduan3", sortable: True, width: 50}]); var grid = new Ext. grid. gridpanel ({renderto: "div1", // in which layer the title is displayed: "the title to be written here", // The title Height: 200, width: 580, CM: colm, // The column header to be loaded store: store, // The data to be loaded autoexpandcolumn: 2}); store. load (); // do not forget to write; otherwise, data is not loaded });
Page
<Div id = "div1"> </div>
Struts2 action
Public String execute () throws exception {list <mapleftinfosview> List = NULL; try {If (areaname! = NULL &&! Areaname. equalsignorecase ("null") & areaname. trim (). length ()> 0) {string name = new string (areaname. getbytes ("ISO-8859-1"), "UTF-8"); // transcode the obtained parameter mapleftinfosview v = new mapleftinfosview (); V. setwfname (this. substringareaname (name); List = mapinfos. findmapleftinfosviews (V);} elselist = mapinfos. findmapleftinfosviews (null);} catch (exception e) {MSG = "failed to get data! "; E. printstacktrace (); Return" sorry ";}if (list! = NULL) {system. out. println (list. size (); response. setcontenttype ("text/XML; charset = UTF-8"); response. setcharacterencoding ("UTF-8"); printwriter PW = NULL; try {PW = response. getwriter ();} catch (ioexception e) {e. printstacktrace ();} stringbuffer sb = new stringbuffer (); sb. append ("<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> "); Sb. append ("<items>"); For (INT I = 0; I <list. size (); I ++) {mapleftinfosview v = List. get (I); sb. append ("<item>"); // note that the record attribute in item and JS is consistent with sb. append ("<ziduan0> "). append (v. getwfid ()). append ("</ziduan0>"); sb. append ("<ziduan1> "). append (v. getwfname ()). append ("</ziduan1>"); sb. append ("<ziduan2> "). append (v. getallcapacity ()). append ("</ziduan2>"); sb. append ("<ziduan3> "). append (v. getwfp ()). append ("</ziduan3>"); sb. append ("</item>");} sb. append ("</items>"); string xmldbtree = sb. tostring (); PW. print (xmldbtree); PW. flush (); PW. close ();} return NULL ;}