title: How to send String value back to Spring MVC?
body: <h2>Problem</h2>
  
  <p>My view has two forms:</p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;form:form method="post" action="/insertChapter" modelAttribute="Chapter"&gt;
  &lt;form:input type="hidden" path="chapter" value="${info.chapter}"/&gt;
  &lt;form:input path="title" /&gt;
  &lt;input type="submit" value="Insert" /&gt;
  &lt;/form:form&gt;
  
  &lt;form:form method ="GET" action="/deleteChapter" modelAttribute="What is here?"&gt;
  &lt;form:hidden path = "chapter" value ="${info.chapter}"/&gt;
  &lt;input type="submit" value="Delete Chapter ${info.chapter}" /&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@RequestMapping("/insertChapter")
  public String insertChapter(@ModelAttribute Chapter chapter) {
      if (chapter != null)
          infoService.insertChapter(chapter.getChapter(), chapter.getChapter());
          return "redirect:/getInfoListList";
  }
  @RequestMapping("/deleteChapter")
  public String deleteChapter(@RequestParam String chapter) {
      infoService.deleteChapter(chapter);
      return "redirect:/getInfoListList";
  }
  </code></pre>
  
  <p>but the server complained: </p>
  
  <blockquote>
    <p>An exception occurred processing JSP page .. in line 62</p>
  </blockquote>
  
  <pre><code>Neither BindingResult nor plain target object for bean name 'chapter' available as request attribute
  </code></pre>
  
  <p>and then</p>
  
  <blockquote>
    <p>Neither BindingResult nor plain target object for bean name 'command'
    available as request attribute</p>
  </blockquote>
  
  <h2>Question / Answers</h2>
  
  <p>So what is the correct way to set the value of a hidden field?  My controller needs to know the value and the value is not constant because I have different values in different forms.  </p>
  
  <p>Anything I need to do for the Chapter to be automatically delivered to the controller? </p>
  
  <p>And when to use form:input and when to use just input?  I see sometimes the examples online just use <code>&lt;input ...&gt;</code> instead of <code>&lt;form:input&gt;</code></p>
  
  <h2>Answer:</h2>
  
  <p>It seems that I should use ModelAttribute in the controller which generates the first page (in addition to the one for processing the post).</p>
  
  <h2>Additional Questions</h2>
  
  <p>Then it comes with a second question, how to let the controller handle a String ModelAttribute, and how to set let Chapter and String be handled?  Is the following function sufficient?</p>
  
  <pre><code>@RequestMapping("/getInfoListList")
  public ModelAndView getInfoListList(@ModelAttribute Chapter chapter, @ModelAttribute String chaptertobedeleted) {
      List&lt;List&lt;Info&gt;&gt; infoList = infoService.getInfoListList();
      ModelAndView aModel =new ModelAndView("infoListList", "infoListList", infoList);
      return aModel;
  }
  </code></pre>