Spring MVC processing Ajax

Source: Internet
Author: User

 

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 ;}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.