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

struts2 json插件执行原理 action执行两次
用struts2+json开发项目,发现调用其中的一个方法(getChildDepartment())莫明其秒的执行了两次,而另一个方法也莫明其秒的自已执行了。

debug了半天,原因是我用JSON插件把返回结果定为JSON了。而JSON的原理是在ACTION中的get方法都会序列化,所以前面是get的方法只要没指定不序列化,都会执行

解决方法

1、Action中的业务方法前别加get 或者 set(属性的get set 除外)
2、用@JSON(serialize=false)指定方法不序列化



import com.googlecode.jsonplugin.annotations.JSON;

@JSON(serialize=false)
public String getChild() throws Exception{ 
..............
   ..............
   return "success";
 
}