title: How to make HTML Button perform action in Java?
body: <p>Basically I'm creating an upvote/downvote system, Now I've created two buttons in HTML : </p>
  
  <pre><code>&lt;button type="button" name="upvote"&gt;&lt;/button&gt;
  &lt;br&gt;
  &lt;input type="number" th:value = "${commentValue}" disabled&gt;
  &lt;br&gt;
  &lt;button type="button" name="downvote"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>First button with name attribute - "upvote" and second with "downvote" , Now I want to catch a click on button and change the <strong>commentValue</strong> accordingly, <strong>If user clicks upvote, comment value must incriment and on downvote it must decrement</strong></p>
  
  <p>I found some topics that said to implement ActionListener, Create JButton objects and etc. but isn't there any simpler way ? </p>
  
  <p>This is my code right now, The buttons do nothing. :</p>
  
  <blockquote>
    <p>Controller : </p>
  </blockquote>
  
  <pre><code>private int numberValue = 0;
  
  @GetMapping("/check")
  public String nuberCheck(Model model){
  
      model.addAttribute("commentValue", numberValue);
  
      return "numberCheck";
  }
  
  @PostMapping("/check")
  public String upvote(Model model, @RequestParam String action){
      if (action == "upvote"){
          numberValue++;
          model.addAttribute("commentValue", numberValue);
      }else if (action == "downvote"){
          numberValue --;
          model.addAttribute("commentValue", numberValue);
      }
      return "numberCheck";
  
  }
  </code></pre>
  
  <blockquote>
    <p>numberCheck : </p>
  </blockquote>
  
  <pre><code>&lt;form action="#" th:action="@{/check}" method="post"&gt;
      &lt;button type="button" name="action" th:value="upvote" th:text = "upvote"&gt;&lt;/button&gt;
      &lt;br&gt;
      &lt;input type="number" th:value = "${commentValue}" disabled&gt;
      &lt;br&gt;
      &lt;button type="button" name="action" th:value = "dowvnote" th:text = "dowvnote"&gt;&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>FIXED</strong></p>
  
  <p>Change button types to "submit" and then in controller : </p>
  
  <pre><code>@PostMapping("/check")
  public String check(Model model,@RequestParam String action) {
  
      System.out.println(action);
  
      if (action.equals("upvote")) {
          numberValue++;
          model.addAttribute("numberValue", numberValue);
      }
  
      if (action.equals("dowvnote")) {
          numberValue--;
          model.addAttribute("numberValue", numberValue);
      }
      return "numberCheck";
  }
  </code></pre>
  
  <p><code>@RequestParam String action</code> "action" is the name attribute of button and "save" and "cancel" are the "value" attributes :) hope it helps</p>