---
title: "struts2 ajax 方法执行两次"
author: "tdmlxq"
date: "2010-06-25T18:58:17Z"
tags: ["Ajax", "json"]
categories: ["企业架构"]
slug: "struts2-ajax"
draft: false
lastmod: "2010-06-25T19:00:35Z"
id: 699549
url: "https://tdmlxq.iteye.com/blog/699549"
---

struts2中使用json插件执行ajax处理时，如果方法名是get方法的时候，方法会莫名其妙的执行两次。

原因：

struts2 中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";  
   
}