title: how to take data from a Java servlet and put it on an existent html page
body: <p>edit: i have already read this question "How to use Servlets and Ajax?" it talks about generating something in the same page, i want to take data from the page to the servlet then redirect to another page and fill some existing text areas.</p>
  
  <p>Hi i'm new on stackoverflow and i am new in programming. I'm doing a web app where i have to search something from an html page to the db, and this is not a problem.</p>
  
  <p>The problem is that when the ajax call produces the data i have to create a button too that redirects me to an existing html page, at the same time the button have to send the data to load in the other page to the servlet (i have already done this, it now produces the json but i don't know how to insert it into the other page) and i don't know how to say to the servlet "hey take this little data from the search page, find the record and load the edit page with the data i want in!".</p>
  
  <p>I prefer to not use a JSP but if it is the only way..</p>
  
  <p>these are the buttons in the search function:</p>
  
  <pre><code>&lt;form&gt;
      &lt;button name="delA" class="btn btn-danger" type="submit" value="' + data[i].key + '" formaction="delete" formmethod="post" onclick="clickedConfirm(event)"&gt;&lt;/button&gt;
         &lt;span class="glyphicon glyphicon-trash" aria-hidden="true"&gt;&lt;/span&gt;
            &lt;button name="row" class="btn btn-warning" type="submit" value="' + data[i].key + '" href="http://localhost:8080/label-editor/edit.html" formaction="edit" formmethod="get"&gt;&lt;/button&gt;
         &lt;span class="glyphicon glyphicon-pencil" aria-hidden="true"&gt;&lt;/span&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>this is the edit servlet:</p>
  
  <pre><code>protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  
  
  
      LabelManager lm = new LabelManager();
      JSONSerializer js = new JSONSerializer();
      String json = "";
  
      String paramRow = req.getParameter("row");
      ServletOutputStream out = resp.getOutputStream();
  
      if(paramRow != null){
      Collection&lt;LabelModel&gt; label = null;                        
  
      label = lm.searchLabelK(paramRow);
  
          json = js
  
                  .exclude("*.class")
                  .exclude("locale.ISO3Language")
                  .exclude("locale.baseLocale")
                  .exclude("locale.country")
                  .exclude("locale.displayCountry")
                  .exclude("locale.displayLanguage")
                  .exclude("locale.displayScript")
                  .exclude("locale.displayVariant")
                  .exclude("locale.language")
                  .exclude("locale.localeExtensions")
                  .exclude("locale.script")
                  .exclude("locale.variant")
                  .serialize(label);
  
          resp.setContentType("application/json");
  
          out.print(json);
          out.flush();
  
      }
  }
  </code></pre>
  
  <p>I was thinking about an ajax call like this but i don't know how to complete it, i cant find anything that could help:</p>
  
  <pre><code>function editlabel() {
      $.ajax({
          url : 'edit',
          data : {
              row : getUrlParameter('row')
          },
          success : function(data, status, xhr) {
              $('#edit').submit(function(response) {
                  if (data.length &gt; 0) {
  
                      $('#key').val(data[0].key)
  
                      console.log("stampo il titolo");
  
                      for (var i = 1; i &lt; data.key.length; i++) {
  
                          var row = data[i];
  
                          $('#val' + i).val(row.value)
  
                          console.log("ciclo " + row);
  
                      }
  
                  }
              });
  
          },
          error : function(req, status, err) {
              console.log('Something went wrong', status, err);
          }
      });
  }
  </code></pre>
  
  <p>Thank you for your time and your help 
  p.s. sorry for my bad english</p>