title: How to send JSON data from JSP page to action class in Struts2 using AJAX
body: <p>I want to transfer json data from jsp page to action class using ajax in jquery.
  Following is the jquery code.</p>
  
  <pre><code>$.ajax({
  type : 'POST',
  url : contextPath+"/postData.action",   
  async: false ,
  data :json,
  dataType:"json", 
  contentType: 'application/json; charset=utf-8',
  contentType: "application/json",
  success : function(result) {
      }
  });
  </code></pre>
  
  <p>Follwing is the Action Class Code:</p>
  
  <pre><code>private String data;
  
  public String getData() {
      return data;
  }
  
  public void setData(String data) {
      this.data = data;
  }
  
  @Override
  public String execute() 
  {
      System.out.println(data);
      return ActionSupport.SUCCESS;
  }
  </code></pre>
  
  <p>Struts.xml config  file </p>
  
  <pre><code>&lt;action name="postData" class="demo.StoreJSONData" &gt;     
      &lt;result name="success"&gt;/jsp/output.jsp&lt;/result&gt;
  
   &lt;/action&gt;
  </code></pre>
  
  <p>Code of sample json code:</p>
  
  <pre><code>{
  "rectangle": {
      "0": {
          "id": "rectangle_1",
          "displayData": "&lt;div class=\"\" style=\"background: none repeat scroll 0% 0% rgb(255, 255, 255); width: 389px; height: 129px; position: absolute; left: 92px; top: 360px; border: 1px solid black; z-index: 4;\" id=\"rectangle_1\"&gt;&lt;/div&gt;"
      }
  },
  "eclipse": {
      "0": {
          "id": "eclipse_1",
          "displayData": "&lt;div class=\"\" style=\"position: absolute; z-index: 5; background-color: rgb(243, 239, 15); border: 1px solid black; width: 245px; height: 83px; border-radius: 50% 50% 50% 50%; left: 563px; top: 445px;\" id=\"eclipse_1\"&gt;&lt;/div&gt;"
      }
  }
  }
  </code></pre>