Ext. ajax. request ({URL: 'http: // localhost: 8080/MyApp/exthandler, jsondata: ext. util. JSON. encode (Info), Params: {Action: 'up'}, success: function (resp, opts) {var resptext = ext. util. JSON. decode (resp. responsetext); Ext. MSG. alert ('hprompt ', resptext.info) ;}, failure: function (resp, opts) {var resptext = ext. util. JSON. decode (resp. responsetext); Ext. MSG. alert ('error', resptext. error );}});
CodeThe URL parameter in specifies a java servlet that submits JSON-format data to the servlet for processing through the jsondata parameter. You can also submit other parameters, which are defined in the Params parameter; then Ext. ajax calls the corresponding success or failure callback function for processing;
How can I get the data defined in the jsondata parameter in Servlet? See the following code:
Stringbuffer JSON = new stringbuffer (); string line = NULL; try {bufferedreader reader = Req. getreader (); While (line = reader. Readline ())! = NULL) {// read JSON. append (line);} catch (exception e ){}
The server successfully processes the data and sets the returned information:
RSP. setcontenttype ("text/JSON; charset = UTF-8"); RSP. getwriter (). write ("{success: false, error: 'failed to update information because:" + err + "'}"); RSP. setstatus (httpservletresponse. SC _expectation_failed); // set the failure identifier // The failure callback function will call and execute and output resptext. error Information
Http://hi.baidu.com/jsjok/blog/item/5025573781c0300b90ef39e6.html