Struts2.1.6+jsonplugin(googlecode)

ハマって助けてもらったのでメモ。
2.1.6まではStrtus2公式(?)のJSONプラグインが対応してないのでGoogleCodeのJsonPluginを入れる様子。
そのやり方がよくわかんなかったのでまとめてメモ。

struts.xml

<package name="pjname" extends="xxxx" namespace="/">
  <result-types>
    <result-type name="json" class="com.googlecode.jsonplugin.JSONResult"/>
  </result-types>
  <interceptors>
    <interceptor name="json" class="com.googlecode.jsonplugin.JSONInterceptor"/>
    <interceptor-stack name="defaultStack">
      <interceptor-ref name="json" />
    </interceptor-stack>
    <default-interceptor-ref name="defaultStack" />
  </interceptors>
</package>

●Action

@Results({
    @Result(name="success" , type="json")
})
public class JsonAction extends ActionSupport {
    public String execute() throws Exception {

        resultList = new ArrayList<String>();
        for (int i = 0; i < 9; i++) {
            resultList.add("val" + i);
        }

        return "success";
    }

    private String str; ←リクエスト時に送信されたものが入る。今回は「aaa」って入ってる。
    private List<String> resultList;

    @JSON(name = "result") ←キー名変えたい時だけ設定すればよい。無くてもOK。
    public List<String> getResultList() {
        return resultList;
    }

    public void setResultList(List<String> resultList) {
        this.resultList = resultList;
    }
    public String getStr() {
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }
}

●JS

    $(".selectTag").change( function() {
        $.getJSON(
            'http://localhost:8080/action/name',
            {"str": "aaa"},
            function(data, status) {
                console.log(data);
            }
          );
    }

http://code.google.com/p/jsonplugin/
ここのsourceに書いてあるSVNアドレス直叩きすればtestコードに書いてありました…orz