Today, when I used struts2 asynchronous requests to upload an object from the background to the foreground, I encountered a small problem. Now I am markingCodePaste it as a memo.
Struts. xml
<Action name = "getsystemcontactorinfo" class = "useraction" method = "getsystemcontactorinfo"> <result type = "JSON"> <Param name = "includeproperties"> systemcontactor \. username, systemcontactor \. cellphone, systemcontactor \. notesmail </param> <! -- <Param name = "includeproperties"> systemcontactor </param> is incorrect --> <! -- <Param name = "includeproperties"> systemcontactor. * </param> This is also incorrect --> </result> </Action>
Useraction
Public String getsystemcontactorinfo () {usermodel systemcontactor = new usermodel (); systemcontactor. setusername ("Zhang San"); systemcontactor. setcellphone ("13240151465"); systemcontactor. setnotesmail ("test@126.com"); Return Action. success ;}
Usermodel
Public class usermodel {private string username; private string cellphone; private string notesmail; // The get and set methods are omitted}
JSP page
$. Ajax ({type: 'post', URL: 'getsystemcontactorinfo. action ', datatype: 'json', async: True, success: function showcontent (JSON) {var userinfo = JSON. systemcontactor; $ ("# username" ).html (userinfo. username); $ ("# cellphone" cmd.html (userinfo. cellphone); $ ("# notesmail" cmd.html (userinfo. notesmail );}});
<Param name = "includeproperties"> systemcontactor </param> can be written as this when systemcontactor is a string or number.
<Param name = "includeproperties"> systemcontactor. * </param> this parameter can be set when systemcontactor is set to list.
It is not clear why systemcontactor cannot be written directly when it is an object. Mark it here. Well, it's necessary to go to the official API.