Ajax multi-level linkage (struts1.x and strurts2.x) take the city as an example on the Code :( if there is a problem can add QQ: 2250680083) 1, import package json-lib-2.2.3-jdk15.jar, introduce jquery if the network is recommended to use Google, URL: <SCRIPT src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type = "text/JavaScript"> </SCRIPT> 2. The page code is as follows: var url = "/" + lemis. web_app_name + "/monitor/comeditshi. do "; // initialize the city function inni_city () {jquery. ajax ({URL: URL, data: {method: 'ajaxgetcity'}, type: "Post", async: false, cache: false, datatype: "JSON", success: onchangecallback}); function onchangecallback (data) {var STR = "<option value =''> select </option> "; for (VAR I = 0; I <data. length; I ++) {If (s8 = (data [I]. key) {STR + = "<option selected = true value = '" + data [I]. key + "'>" + data [I]. value + "</option>"; // method for handling IE6 ($ (""). val (value) is faulty)} else {STR + = "<option value = '" + data [I]. key + "'>" + data [I]. value + "</option>" ;}}$ ("# seat ID" 2.16.html (STR) ;}3. configure action (configured by yourself) 4. Java code public class comeditshi extends actionleafsupport {
/***
* Obtain the city
**/
Public actionforward ajaxgetcity (actionmapping mapping, actionform,
Httpservletrequest request, httpservletresponse response) throws appexception, ioexception {
List <param> zihantypes = new arraylist <param> ();
Ajaxdata msg1 = new ajaxdata (); // method of your own
Ajaxdata. Java |
Public class ajaxdata { /** * Provincial/municipal departments for monitoring * @ Author zihan * @ Return */ Public writable hashmap getshi_st (){ Ajaxdatadao RD = new ajaxdatadao (); Try { Return RD. getshi_st (); // method of your own
Public writable hashmap getshi_st () throws sqlexception { Linkedhashmap map = getdata ("ajax_shi", null );
// Zihan county/district Private linkedhashmap getdata (string, string string2 ){ Linkedhashmap map = new linkedhashmap (); Sc01 asc01 = new sc01 (); Sc01 asc01 _ = new sc01 (); Asc01.setfilekey (string ); If (string2! = NULL ){ Asc01.setaab003 (string2 ); } Connection con = NULL; Try { Con = dbutil. getconnection (); List <?> List = (list <?>) Find (con, asc01, null, 0 ); For (INT I = 0; I <list. Size (); I ++ ){ Classhelper. copyproperties (list. Get (I), asc01 _); Map. Put (asc01 _. getaab003 (), asc01 _. getaab300 (); // The main step }
} Catch (noconnectionexception e ){ // Todo auto-generated Catch Block E. printstacktrace (); } Catch (appexception e ){ // Todo auto-generated Catch Block E. printstacktrace (); } Return map;
} |
Return map; } |
} Catch (sqlexception e ){ E. printstacktrace (); } Return NULL; } } |
Linkedhashmap mapaab061 = msg1.getshi _ ST ();
Set <map. Entry <string, string> entryseset = mapaab061.entryset ();
For (Map. Entry <string, string> entry: entryseset ){
Param = new param ();
Param. Java |
Public class Param { Private object entity; // Reserved Private string value; Private string key;
Public param (){ } Public param (string value, string key ){ This. value = value; This. Key = key; } Public String getvalue (){ Return value; }
Public void setvalue (string value ){ This. value = value; }
Public String getkey (){ Return key; }
Public void setkey (string key ){ This. Key = key; }
Public object getentity (){ Return entity; }
Public void setentity (Object entity ){ This. entity = entity; }
} |
Param. setkey (entry. getkey ());
Param. setvalue (entry. getvalue ());
Zihantypes. Add (PARAM );
}
Jsonarray jsonobj = jsonarray. fromobject (zihantypes );
Sendmsg (jsonobj. tostring (), response); // structs1.x // sendmsg (jsonobj. tostring (); // structs2.x
Structs1.x |
Structs2.x |
Private void sendmsg (string, httpservletresponse response ){ // Todo auto-generated method stub Response. setcharacterencoding ("UTF-8 "); Try { Response. getwriter (). Write (string ); } Catch (ioexception e ){ // Todo auto-generated Catch Block E. printstacktrace (); }
} |
Private void sendmsg (string ){ Httpservletresponse response = servletactioncontext. getresponse (); Response. setcharacterencoding ("UTF-8 "); Response. getwriter (). Write (string ); } |
Return NULL;
}
} 5. The jquery onchange event is okay for the corresponding cascade method! 6. Have a good time sharing technologies!