title: How to pass variable value from web form to another web page via controller class?
body: <p>Main class:</p>
  <pre><code>package com.example.handlingformsubmission;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class HandlingFormSubmissionApplication {
  
  public static void main(String[] args) {
  SpringApplication.run(HandlingFormSubmissionApplication.class, args);
  }
  
  }
  </code></pre>
  <p>Controller:(here in Post mapping something wrong with code which is supposed to pass values of variable to another page, but it doesn't):</p>
  <pre><code>package com.example.handlingformsubmission;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.*;
  
  @Controller
  public class GreetingController {
  
  @GetMapping(&quot;/z.html&quot;)
  public String greetingForm(Model model) {
  model.addAttribute(&quot;z.html&quot;, new Greeting());
  return &quot;z.html&quot;;
  }
  @GetMapping(&quot;/zu.html&quot;)
  public String greetingForm2(Model model) {
  model.addAttribute(&quot;zu.html&quot;, new Greeting());
  return &quot;zu.html&quot;;
  }
  
  @GetMapping(&quot;/zus.html&quot;)
  public String greetingForm3(Model model) {
  model.addAttribute(&quot;zus.html&quot;, new Greeting());
  return &quot;zus.html&quot;;
  }
  
  @GetMapping(&quot;/zusu.html&quot;)
  public String greetingForm4(Model model) {
  model.addAttribute(&quot;zusu.html&quot;, new Greeting());
  return &quot;zusu.html&quot;;
  }
  @PostMapping(&quot;/zusu_generated.html&quot;)
  public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
  model.addAttribute(&quot;zusu_generated.html&quot;,greeting);
  model.addAttribute(&quot;Unit&quot;, greeting.getUnit());
  model.addAttribute(&quot;Restarttype&quot;, greeting.getRestarttype());
  return &quot;zusu_generated.html&quot;;
  }
  
  }
  </code></pre>
  <p>Class where variables are declared (and getters and setters are configured):</p>
  <pre><code>package com.example.handlingformsubmission;
  public class Greeting {
  public String Restarttype;
  public String Unit;
  
  public String getRestarttype() {
  return Restarttype;
  }
  
  public void setRestarttype(String Restarttype) {
  this.Restarttype = Restarttype;
  }
  
  public String getUnit() {
  return Unit;
  }
  
  public void setUNIT(String Unit) {
  this.Unit = Unit;
    }
  }
  </code></pre>
  <p>HTML web page where web form accepts values of variable:</p>
  <pre><code>    &lt;!DOCTYPE HTML&gt;
  
      &lt;html xmlns:th=&quot;https://www.thymeleaf.org&quot; xmlns:form=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
      &lt;head&gt;
      &lt;title&gt;Getting Started: Handling Form Submission&lt;/title&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;css.css&quot; /&gt;
      &lt;style type=&quot;text/css&quot;&gt;
  
      .block1 {
      width: 20px;
      background: #ffffff;
      padding: 5px;
      padding-right: 20px;
      border: solid 1px white;
      float: left;
      margin-top: 17%; /* Отступ сверху */
      }
  
      .block2 {
      width: 1360px;
      background: #ffffff;
      padding: 5px;
      padding-right: 20px;
      border: solid 1px black;
      float: left;
      margin-top: 17%; /* Отступ сверху */
      text-align:center;
      }
  
      .block3 {
      width: 20px;
      background: #ffffff;
      padding: 5px;
      padding-right: 20px;
      border: solid 1px white;
      float: left;
      margin-top: 17%; /* Отступ сверху */
      }
  
     a.hover: underline(none)
  
      &lt;/style&gt;
  
  
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;block1&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;block2&quot;&gt;
          &lt;h1&gt;Nokia BSC3i ZUSU command&lt;/h1&gt;
  
          &lt;form action=&quot;#&quot; th:action=&quot;@{/zusu_generated.html}&quot; th:object=&quot;${greeting}&quot; method=&quot;post&quot;&gt;
              &lt;table align = center&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt; ZUSU:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;label for=&quot;Unit&quot;&gt;Unit:&lt;/label&gt;
                      &lt;select name=&quot;Unit&quot; id=&quot;Unit&quot;&gt;
                          &lt;optgroup label=&quot;Unit&quot;&gt;
                              &lt;option value=&quot;BCSU&quot;&gt;BCSU&lt;/option&gt;
                              &lt;option value=&quot;Clock&quot;&gt;Clock&lt;/option&gt;
                              &lt;option value=&quot;ET&quot;&gt;ET&lt;/option&gt;
                          &lt;/optgroup&gt;
                      &lt;/select&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                  C
                  &lt;/td&gt;
                  &lt;td&gt; = &lt;/td&gt;
                  &lt;td&gt;
                      &lt;label for=&quot;Restart value&quot;&gt; &lt;/label&gt;
                      &lt;select name=&quot;Restart type&quot; id=&quot;Restart value&quot;&gt;
                          &lt;optgroup label=&quot;Restart type&quot;&gt;
                              &lt;option value=&quot;TOT&quot;&gt;TOT&lt;/option&gt;
                              &lt;option value=&quot;HALF&quot;&gt;HALF&lt;/option&gt;
                              &lt;option value=&quot;PARTIAL&quot;&gt;PARTIAL&lt;/option&gt;
                          &lt;/optgroup&gt;
                      &lt;/select&gt;
                  &lt;/td&gt;
  
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Generate command&quot; /&gt; &lt;input type=&quot;reset&quot; value=&quot;Reset&quot; 
      /&gt;&lt;/p&gt;
          &lt;/form&gt;
      &lt;/div&gt;
      &lt;div class=&quot;block3&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  <p>HTML web page where variable values should appear, but they don't appear:</p>
  <pre><code>    &lt;!DOCTYPE HTML&gt;
  
      &lt;html xmlns:th=&quot;https://www.thymeleaf.org&quot; xmlns:form=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
      &lt;head&gt;
      &lt;title&gt;Getting Started: Handling Form Submission&lt;/title&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;css.css&quot; /&gt;
      &lt;style type=&quot;text/css&quot;&gt;
  
     .block1 {
      width: 20px;
      background: #ffffff;
      padding: 5px;
      padding-right: 20px;
      border: solid 1px white;
      float: left;
      margin-top: 17%; /* Отступ сверху */
      }
  
     .block2 {
      width: 1360px;
      background: #ffffff;
      padding: 5px;
      padding-right: 20px;
      border: solid 1px black;
      float: left;
      margin-top: 17%; /* Отступ сверху */
      text-align:center;
      }
  
     .block3 {
      width: 20px;
      background: #ffffff;
      padding: 5px;
      padding-right: 20px;
      border: solid 1px white;
      float: left;
      margin-top: 17%; /* Отступ сверху */
      }
  
     a.hover: underline(none)
  
      &lt;/style&gt;
  
  
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;block1&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;block2&quot;&gt;
          &lt;h1&gt;Nokia BSC3i ZUSU command&lt;/h1&gt;
  
          &lt;form action=&quot;#&quot; th:action=&quot;@{/greeting}&quot; th:object=&quot;${greeting}&quot; method=&quot;post&quot;&gt;
              &lt;table align = center&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;ZUSU:&lt;/td&gt;
                      &lt;td&gt;
                          &lt;label for=&quot;Unit&quot;&gt;Unit:&lt;/label&gt;
                          &lt;select name=&quot;Unit&quot; id=&quot;Unit&quot;&gt;
                              &lt;optgroup label=&quot;Unit&quot;&gt;
                                  &lt;option value=&quot;BCSU&quot;&gt;BCSU&lt;/option&gt;
                                  &lt;option value=&quot;Clock&quot;&gt;Clock&lt;/option&gt;
                                  &lt;option value=&quot;ET&quot;&gt;ET&lt;/option&gt;
                              &lt;/optgroup&gt;
                          &lt;/select&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          C
                      &lt;/td&gt;
  
  
  
                      &lt;td&gt; = &lt;/td&gt;
                      &lt;td&gt;
  
                          &lt;label for=&quot;Restart value&quot;&gt; &lt;/label&gt;
                          &lt;select name=&quot;Restart type&quot; id=&quot;Restart value&quot;&gt;
                              &lt;optgroup label=&quot;Restart type&quot;&gt;
                                  &lt;option value=&quot;TOT&quot;&gt;TOT&lt;/option&gt;
                                  &lt;option value=&quot;HALF&quot;&gt;HALF&lt;/option&gt;
                                  &lt;option value=&quot;PARTIAL&quot;&gt;PARTIAL&lt;/option&gt;
                              &lt;/optgroup&gt;
                          &lt;/select&gt;
                      &lt;/td&gt;
  
                  &lt;/tr&gt;
                  &lt;tr&gt;
  
                      &lt;td&gt;
                          &lt;p th:text=&quot;'Generated command is: ZUSU: UNIT = ' + ${greeting.Unit} + ' C = ' + ${greeting.Restarttype}&quot; /&gt;
  
                      &lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;/table&gt;
              &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Copy to memory&quot; /&gt; &lt;input type=&quot;reset&quot; value=&quot;Reset&quot; /&gt; 
      &lt;/p&gt;
          &lt;/form&gt;
  
  
  
      &lt;/div&gt;
      &lt;div class=&quot;block3&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>