日期:2014-05-16  浏览次数:20335 次

Struts2 一个action支持xml或者json返回
action配置中配置xml返回与json返回
<action name="xx" class="xx" method="xx">
   <result name="xmlMessage" type="plainText"></result>
   <result name="json" type="json">
        <param name="root">ajaxJson</param>
    </result>
</action>

public String retXmlOrJson() {
String returnType = null; //返回xml
if(要返回JSON ) {
returnType = "json";  //返回json
}
return returnType
}