Struts2 JSON transfer object

Source: Internet
Author: User

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.

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.