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
}

猜你喜欢

转载自weijs.iteye.com/blog/2054201