title: How to send data from one jsp to another jsp and display data using ajax
body: <p>I'm very new to ajax and jquery. I have a problem when using jsp and ajax to send data.</p>
  
  <p>I know how to display result (Here I use a table) in the same page using ajax.</p>
  
  <p>Now I want to click a button in the first jsp (the click button uses ajax to call servlet controller so as to get data from database, and then converting the data to json format), then show the result in the second jsp, but I was stuck how to do it. </p>
  
  <p>Here's the code:</p>
  
  <p><strong>test.jsp</strong></p>
  
  <pre><code> &lt;body&gt;
       &lt;input type='button' value='Show' id='ShowButton' /&gt;
   &lt;/body&gt;
   &lt;script type='text/javascript'&gt;
      $(document).ready(function() {
          $("#ShowButton").click(function(event) {
              $.ajax({
                  type : "POST",
                  url : "controller.view",
                  dataType : "json",
                  success : function(data) {
                      $.each(data, function (index, element) {
                          var showContent = '';
                          showContent += '&lt;tr&gt;&lt;td&gt;' + element.cpId + '&lt;/td&gt;
                                          &lt;td&gt;' + element.cpName + '&lt;/td&gt;&lt;td&gt;' 
                                          + element.createDate + '&lt;/td&gt;&lt;td&gt;' + 
                                          element.enable + '&lt;/td&gt;&lt;/tr&gt;';
                          $("#content tbody").append(showContent);           
                      });
                  }
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>test2.jsp</strong></p>
  
  <pre><code>&lt;body&gt;
  &lt;div &gt;
      &lt;table id='content'&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;ID&lt;/th&gt;
                  &lt;th&gt;Content Provider Name&lt;/th&gt;
                  &lt;th&gt;Create Date&lt;/th&gt;
                  &lt;th&gt;Enable&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Thanks. </p>