title: how to transfer data from sun to java
body: <p>I have a form for sending first and last name to the js</p>
  <p>index.html</p>
  <pre><code> &lt;body&gt;
         &lt;form name=&quot;loginForm&quot; onsubmit=&quot;createUser()&quot;&gt; 
          &lt;p &gt; Firstname: &lt;/p&gt;
          &lt;input type=&quot;text&quot; name=&quot;firstname&quot; id=&quot;firstname&quot; placeholder=&quot;firstname&quot;/&gt;&lt;br&gt;
          &lt;p &gt; Lastname: &lt;/p&gt;
          &lt;input type=&quot;lastname&quot; name=&quot;lastname&quot; id=&quot;lastname&quot; placeholder=&quot;lastname&quot;/&gt;&lt;br&gt;
          &lt;input id=&quot;loginButton&quot; type=&quot;submit&quot; value=&quot;Create User&quot; &gt;
      &lt;/form&gt;
         &lt;script&gt; 
             function createUser() {
              let firstname = document.forms['loginForm'].elements['firstname'].value;
              let lastname = document.forms['loginForm'].elements['lastname'].value;
                  }
      
            createUser();
       &lt;/script&gt;
  </code></pre>
  <p>I want that when the create user button is clicked, the data is transferred to the backend and the user is created there.</p>
  <pre><code>   @PostMapping(value = &quot;/save&quot;, consumes = MediaType.APPLICATION_JSON_VALUE)
      public void save(@RequestBody Person person) {
          personService.save(person);
      }
  </code></pre>
  <p>i don't understand how to redirect data from js to java.</p>
  <p>I use MVC and spring boot</p>