Packagecom.hyy.action;ImportJava.util.HashMap;ImportJava.util.Map;Importorg.apache.struts2.convention.annotation.Action;ImportOrg.apache.struts2.convention.annotation.ParentPackage;ImportOrg.apache.struts2.convention.annotation.Result;ImportOrg.apache.struts2.json.annotations.JSON;/*** Use Convention plugin and JSON plugin to return action return JSON * Premise: Struts-json-plugin.jar package *@authorHe Yiyong * August 8, 2014*/@ParentPackage ("Json-default") Public classjsonaction {PrivateMap<string,string>map; @Action (Results= {@Result (type= "JSON"))}) PublicString jsontest () {map=NewHashmap<string,string>(); Map.put ("Status", "OK"); Map.put ("Data", "haha"); return"Success"; } @JSON PublicMap<string, string>Getmap () {returnmap; }}
@ParentPackage ("Json-default") is required and must inherit the Json-default package, otherwise the JSON cannot be returned
@Action (results = {@Result (type= "JSON")}) tells struts to return JSON data instead of a view