title: Spring How to redirect when button clicked and how to print to console when another button clicked?
body: <p>This is my controller:</p>
  
  <pre><code>@Controller
  public class StoreController {
      @RequestMapping("/index")
      public String index() {
          return "index";
      }
  
      @RequestMapping("/addProduct")
      public String addProduct() {
          return "addProduct";
      }
  
      @RequestMapping("/print")
      public void print() {
          System.out.println("Printed");
      }
  
      @RequestMapping("/redirectToAddProd")
      public String redirectToAddProd() {
          return "redirect:addProduct";
      }
  }
  </code></pre>
  
  <p>This is my index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Store&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;a href="addProduct.html"&gt;Add new product&lt;/a&gt;
  
      &lt;form action="#" th:action="@{/redirectToAddProd}"&gt;
          &lt;input type="submit" value="Submit"/&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my addProduct.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Add a product&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="#" th:action="@{/print}"&gt;
          &lt;button type="submit"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My store-servlet.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans     
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;context:component-scan base-package="com.ecommerce.store" /&gt;
  
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/static/" /&gt;
          &lt;property name="suffix" value=".html" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>And finally my web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
      &lt;display-name&gt;MyStore&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;store&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;store&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/index.html&lt;/url-pattern&gt;
          &lt;url-pattern&gt;/addProduct.html&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>So, I got two problems.</p>
  
  <ol>
  <li><p>In index.html, why the href method works and the button method redirecting does not work?</p></li>
  <li><p>In addProduct.html how can I print to the console when button pressed?</p></li>
  </ol>
  
  <p>Thankyou guys, hope you can help me.</p>
  
  <p>EDIT:
  Hey guys, I discovered onde thing. My problem could be with Tomcat.
  I don't know why but sometimes my Tomcat is not deploying.
  In my index.html I add a new button for example, publish to the server, run the server and the button is not appearing. Do someone know any solution to this? I disabled auto deploy (but with auto deploy not working to).
  And I'm running on Spring Tool Suit (eclipse)
  Thank you</p>