Ajax is an asynchronous transmission method for Web pages. No matter how powerful it is, it is nothing more than sending a page request. The server processes the request. Therefore, whether it is servlet or spring MVC, it is no different from sending an asynchronous transmission request to the page. Therefore, the same is true for the server. The server does not need to return a page, so the return value of the method for processing the request is null, or the return value is not required. The method content can be written as servlet, that is, printwriter is used to output string or XML text...
The page code is as follows. jquery is used here:
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <HTML>
The server code is as follows:
Public class testajaxaction implements controller {public modelandview handlerequest (httpservletrequest request, httpservletresponse response) throws exception {response. setcharacterencoding ("UTF-8"); string name = request. getparameter ("name"); string Password = request. getparameter ("password"); system. out. println (name + ":" + password); printwriter out = response. getwriter (); List <Map <string, string> List = new arraylist <Map <string, string> (); Map <string, string> m1 = new hashmap <string, string> (); m1.put ("activityid", "000001"); m1.put ("activityname", "Stephen 1 "); map <string, string> m2 = new hashmap <string, string> (); m2.put ("activityid", "000002"); m2.put ("activityname ", "Stephen 2"); Map <string, string> m3 = new hashmap <string, string> (); m3.put ("activityid", "000003 "); m3.put ("activityname", "aststephen 3"); Map <string, string> M4 = new hashmap <string, string> (); m4.put ("activityid ", "000004"); m4.put ("activityname", "Stephen 4"); Map <string, string> M5 = new hashmap <string, string> (); m5.put ("activityid", "000005"); m5.put ("activityname", "Stephen 5"); list. add (M1); list. add (m2); list. add (m3); list. add (M4); list. add (M5); string S = jsonarray. fromobject (list ). tostring (); out. print (s); out. close (); return NULL ;}}