Due to development needs, jquery Ajax technology is recently used in the struts2 framework. Taking Form submission as an example, the following is a summary: 1. jsp file <SCRIPT type = "text/JavaScript" src = "JS/jquery-1.9.1.min.js"> </SCRIPT> <SCRIPT type = "text/JavaScript" >$ (function () {$ ("# btn1 "). click (function (){
$. Ajax ({
URL: 'ajaxactionname. action', // submit the target and process the action in the background.
Datatype: 'json ',
Type: 'post ',
Data: {txtstr: $ ("# TXT"). Val ()}, // obtain the value of the text box as a parameter
Success: showresult // set the action function after successful action execution}) ;}); function showresult (data) // data is the value returned by action {alert (data. result ); // result is a variable used as the return value in action} </SCRIPT> <input id = "TXT" type = "text"/> <br> <input id = "btn1" type = "button" value = "btn1"/> 2. struts. XML <package name = "test" extends = "JSON-Default"> <action name = "ajaxactionname" class = "com. btnaction "> <result type =" JSON "> </result> </Action> </package> 3. Action: btnaction. javapackage com; import COM. opensymphony. xwork2.actionsupport; public class btnaction extends actionsupport {private string result; private string txtstr; Public String getresult () {return this. result;} public void setresult (string TMP) {This. result = TMP;} Public String gettxtstr () {return this.txt STR;} public void settxtstr (string TMP) {This. btn1 = TMP;} Public String execute () throws exception {This. result = This. btn1; // obtain the value of the sent text box, assign it to the result variable, and return it to ajaxreturn success ;}}