To return the json data of an object in struts
[Html]
<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
UserInfo
</Result>
</Action>
<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
UserInfo
</Result>
</Action>
The returned result is the json data of all member variables of the entire action class. To return the data of the userInfo object, you must define the return parameter as the root object.
[Html]
<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
<Param name = "root">
UserInfo
</Param>
</Result>
</Action>
<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
<Param name = "root">
UserInfo
</Param>
</Result>
</Action>
The following are definitions of returned json data.
[Html]
<! -- Encapsulate all methods starting with get -->
<Result type = "json" name = "user">
</Result>
<! -- Only include the user. id attribute -->
<Result type = "json" name = "user">
<Param name = "includeProperties">
User \. id
</Param>
</Result>
<! -- Return the user's JSON List, where userInfosList is a List type attribute in action, userInfosList \ [\ d + \] \. userName indicates that the object stored in userInfosList is 0 .. end's userName attribute (the objects stored in the list must have the userName attribute)
-->
<Result name = "success" type = "json">
<Param name = "includeProperties">
UserInfosList \ [\ d + \] \. userName, userInfosList \ [\ d + \] \. password
</Param>
</Result>
<! -- Does not contain the user attribute -->
<Result type = "json" name = "list">
<Param name = "excludeProperties">
User
</Param>
</Result>
<! -- The root object only contains user -->
<Result type = "json">
<Param name = "root">
User
</Param>
</Result>
<! -- The field (attribute) of the parent class in the "root" object will not (yes ?) JSON data is stored by default. If you do not want to do this, you must specify ignoreHierarchy as false during configuration: -->
<Result type = "json">
<Param name = "ignoreHierarchy"> false </param>
</Result>
<! -- Encapsulate all methods starting with get -->
<Result type = "json" name = "user">
</Result>
<! -- Only include the user. id attribute -->
<Result type = "json" name = "user">
<Param name = "includeProperties">
User \. id
</Param>
</Result>
<! -- Return the user's JSON List, where userInfosList is a List type attribute in action, userInfosList \ [\ d + \] \. userName indicates that the object stored in userInfosList is 0 .. end's userName attribute (the objects stored in the list must have the userName attribute)
-->
<Result name = "success" type = "json">
<Param name = "includeProperties">
UserInfosList \ [\ d + \] \. userName, userInfosList \ [\ d + \] \. password
</Param>
</Result>
<! -- Does not contain the user attribute -->
<Result type = "json" name = "list">
<Param name = "excludeProperties">
User
</Param>
</Result>
<! -- The root object only contains user -->
<Result type = "json">
<Param name = "root">
User
</Param>
</Result>
<! -- The field (attribute) of the parent class in the "root" object will not (yes ?) JSON data is stored by default. If you do not want to do this, you must specify ignoreHierarchy as false during configuration: -->
<Result type = "json">
<Param name = "ignoreHierarchy"> false </param>
</Result>