title: Posting JSON from ajax to Struts2 Action
body: <p>Hey I am trying to post JSON from Ajax to Struts2 action class method. Little more info: I am running client on WAMP server and Struts2 on Eclipse Tomcat.</p>
  
  <p>My client side code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  var dataObj = {
  "data": [{
      "id": "1",
      "name": "Chris"
  }, {
      "id": "2",
      "name": "Kate"
  }, {
      "id": "3",
      "name": "Blade"
  }, {
      "id": "4",
      "name": "Zack"
  }]
  };
  
  var data1 = JSON.stringify(dataObj);
  $(document).ready(function(){
  $("button").click(function(){
  $.ajax({url:"http://localhost:8080/Core/add",type: "post", data:  data1, dataType: 'json',      contentType:"application/json;charset=utf-8",async: true,success:function(result){
    $("#div1").html(result);
  }});
  });
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="div1"&gt;&lt;h2&gt;Let jQuery AJAX Change This Text&lt;/h2&gt;&lt;/div&gt;
  &lt;button&gt;Get External Content&lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;  
  </code></pre>
  
  <p>And this is my Java application stuff:</p>
  
  <p><strong><code>struts.xml</code>:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
  "http://struts.apache.org/dtds/struts-2.1.7.dtd"&gt;
  
  
  
  &lt;struts&gt;
  
         &lt;package name="addMenu" namespace="/" extends="json-default"&gt;
  
        &lt;action name="registrate" class="com.coreRestaurant.menu.MenuAction"&gt;
            &lt;result type="json" &gt;
            &lt;param name="root"&gt;json&lt;/param&gt;
            &lt;/result&gt;
        &lt;/action&gt;
  
        &lt;action name="read" class="com.coreRestaurant.menu.MenuAction" method="readMenuById"&gt;
            &lt;result type="json" &gt;
            &lt;param name="root"&gt;json&lt;/param&gt;
            &lt;/result&gt;
        &lt;/action&gt;
  
        &lt;action name="add" class="com.coreRestaurant.menu.MenuAction" method="addMenu"&gt;
           &lt;result type="json" &gt;
           &lt;param name="root"&gt;data&lt;/param&gt;
           &lt;/result&gt;
        &lt;/action&gt;
  
     &lt;/package&gt;
  
  &lt;/struts&gt;
  </code></pre>
  
  <p>And this is my java code (<code>MenuAction.java</code>):</p>
  
  <pre><code>    package com.coreRestaurant.menu;
  
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
  
      import com.google.gson.Gson;
      import com.opensymphony.xwork2.ActionSupport;
      import com.opensymphony.xwork2.ModelDriven;
  
      public class MenuAction extends ActionSupport implements ModelDriven&lt;Menu&gt;, Serializable{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      private Menu menu = new Menu();
  
      private String json;
  
      private List&lt;Menu&gt; data = new ArrayList&lt;Menu&gt;();
  
  
  
      public String execute(){
          MenuService menuService = new MenuService();
          setJson(new Gson().toJson(menuService.getMenuNames()));
          if(menuService.isDatabaseConnectionDown()==false){
              return SUCCESS;
          }else{
              setJson(new Gson().toJson("Failed to connect to Database"));
              return ERROR;
          }
      }
  
      public String readMenuById(){
          MenuService menuService = new MenuService();
          setJson(new Gson().toJson(menuService.getSpecificalMenuNameById(menu.getId())));
          return SUCCESS;
  
      }
  
      public String addMenu(){
          MenuService menuService = new MenuService();
          System.out.println(data);
          for(int i=0; i&lt;data.size(); i++){
              System.out.println(data.get(i));
          }
          menu.setName("Postitus");
          menuService.addMenu(menu);
          return SUCCESS;
      }
  
      public String getJson() {
          return json;
      }
  
  
      public void setJson(String json) {
          this.json = json;
      }
  
  
      @Override
      public Menu getModel() {
          return menu;
      }
  
      public List&lt;Menu&gt; getData() {
          System.out.println("Getter Call");
          return data;
      }
  
      public void setData(List&lt;Menu&gt; data) {
          System.out.println("Setter Call Flow");
          this.data = data;
      }
  
  }
  </code></pre>
  
  <p>And the <code>Menu.java</code> itself:</p>
  
  <pre><code>package com.coreRestaurant.menu;
  
  import java.io.Serializable;
  
  public class Menu implements Serializable{
  
  
  private static final long serialVersionUID = 1L;
  private String name;
  private int id;
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  }
  </code></pre>
  
  <p>All the time when I run my client side code, I can see the following input only from Eclipse console:</p>
  
  <pre><code>[]
  Getter Call
  </code></pre>
  
  <p>Why is it empty? I expect to have that JSON array from client side but no success. </p>