struts2中action实现ModelDriven后无法返回json的解决方法_JSP教程

编辑Tag赚U币

推荐:Struts2访问servlet分享
Struts2访问servlet分享

复制代码 代码如下:www.mb5u.com

public class DeviceAction extends AbstractAction implements ModelDriven<Device> {
private static Log log = LogFactory.getLog(DeviceAction.class);
private Device device=new Device(); //只能json化 模型驱动的bean
private String result; //无法返回reslut的json值


public String getResult(){
return result;
}
public void setResult(String result){
this.result=result
}
public DeviceDTO getModel() {
return device;
}
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
}

xml配置:

复制代码 代码如下:www.mb5u.com

<action name="queryPu"
class="com.jxj.bss.web.actions.DeviceAction"
method="queryPu">
<interceptor-ref name="isLogin"></interceptor-ref>
<result type="json">
<param name="includeProperties">
resultCode
</param>
</result>
</action>

解决办法:

复制代码 代码如下:www.mb5u.com

<action name="queryPu"
class="com.jxj.bss.web.actions.DeviceAction"
method="queryPu">
<interceptor-ref name="isLogin"></interceptor-ref>
<result type="json">
<param name="root">action</param>
<param name="includeProperties">
resultCode
</param>
</result>
</action>

分享:javaweb之web入门基础
javaweb之web入门基础,需要的朋友可以参考一下

来源:模板无忧//所属分类:JSP教程/更新时间:2013-04-22
相关JSP教程