title: Passing parameters from jsp to Spring Controller method
body: <p>I am working in a Spring MVC application which uses Hibernate. </p>
  
  <p>In the JSP page I have a function which lists the values stored in the database(currently all the value). </p>
  
  <p>I have written a method, where the list is only limited to an ID passed in the JSP file. I got the HQL query working right, so I know it is retrieving data based upon the ID as a parameter.</p>
  
  <p>Now, I would like to use this method in the controller. For that I have to pass a parameter of ID to the list, so in the controller side, the function is called which will retrieve list based upon that ID. </p>
  
  <p>Unfortunately I don't know how to pass parameters from a JSP file.</p>
  
  <p>JSP File :</p>
  
  <pre><code>  &lt;c:url var="addAction" value="/note/add" &gt;&lt;/c:url&gt;
  &lt;form:form action="${addAction}" commandName="notices"&gt;
      &lt;table&gt;
          &lt;c:if test="${!empty notices.notetext}"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;form:label path="noticesid"&gt;
                          &lt;spring:message text="noticesid"/&gt;
                      &lt;/form:label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;form:input path="noticesid" readonly="true" size="8"  disabled="true" /&gt;
                      &lt;form:hidden path="noticesid" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/c:if&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form:label path="notetext"&gt;
                      &lt;spring:message text="notetext"/&gt;
                  &lt;/form:label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;form:input path="notetext"  /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form:label path="notetag" &gt;
                      &lt;spring:message text="notetag"/&gt;
                  &lt;/form:label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;form:input path="notetag"/&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form:label path="notecolor"&gt;
                      &lt;spring:message text="notecolor"/&gt;
                  &lt;/form:label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;form:input path="notecolor" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form:label path="canvasid"&gt;
                      &lt;spring:message text="canvasid"/&gt;
                  &lt;/form:label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;form:input path="canvasid" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form:label path="sectionid"&gt;
                      &lt;spring:message text="sectionid"/&gt;
                  &lt;/form:label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;form:input path="sectionid"  /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form:label path="canvasnName"&gt;
                      &lt;spring:message text="canvasnName"/&gt;
                  &lt;/form:label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;form:input path="canvasnName"  /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
  
          &lt;tr&gt;
              &lt;td colspan="2"&gt;
                  &lt;c:if test="${!empty notices.noticesid}"&gt;
                      &lt;input type="submit"
                             value="&lt;spring:message text="Edit note"/&gt;" /&gt;
                  &lt;/c:if&gt;
                  &lt;c:if test="${empty notices.notetext}"&gt;
                      &lt;input type="submit"
                             value="&lt;spring:message text="Add note"/&gt;" /&gt;
                  &lt;/c:if&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt;
  &lt;br&gt;
  &lt;h3&gt;Notes List&lt;/h3&gt;
  
  &lt;c:url var="listAction" value="/note/list/2323" &gt;&lt;/c:url&gt;
  &lt;c:if test="${!empty notices.noticesid}"&gt;
      &lt;table class="tg"&gt;
          &lt;tr&gt;
              &lt;th width="80"&gt;Notes ID&lt;/th&gt;
              &lt;th width="120"&gt;Notes text&lt;/th&gt;
              &lt;th width="120"&gt;Note Tag&lt;/th&gt;
              &lt;th width="120"&gt;Note color&lt;/th&gt;
              &lt;th width="120"&gt;Note section&lt;/th&gt;
              &lt;th width="120"&gt;Canvas id&lt;/th&gt;
              &lt;th width="120"&gt;Canvas name&lt;/th&gt;
              &lt;th width="120"&gt;Other id&lt;/th&gt;
              &lt;th width="60"&gt;Edit&lt;/th&gt;
              &lt;th width="60"&gt;Delete&lt;/th&gt;
          &lt;/tr&gt;
          &lt;c:forEach items="${listNotes}" var="notices"&gt;
              &lt;tr&gt;
                  &lt;td&gt;${notices.noticesid}&lt;/td&gt;
                  &lt;td&gt;${notices.notetext}&lt;/td&gt;
                  &lt;td&gt;${notices.notetag}&lt;/td&gt;
                  &lt;td&gt;${notices.notecolor}&lt;/td&gt;
                  &lt;td&gt;${notices.sectionid}&lt;/td&gt;
                  &lt;td&gt;${notices.canvasid}&lt;/td&gt;
                  &lt;td&gt;${notices.canvasnName}&lt;/td&gt;
                  &lt;td&gt;${notices.personid}&lt;/td&gt;
                  &lt;td&gt;&lt;a href="&lt;c:url value='/editnote/${notices.noticesid}' /&gt;" &gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;a href="&lt;c:url value='/removenote/${notices.noticesid}' /&gt;" &gt;Delete&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/c:forEach&gt;
      &lt;/table&gt;
  &lt;/c:if&gt;
  </code></pre>
  
  <p>Controller file with list function :</p>
  
  <pre><code>@RequestMapping(value = "/note/list/{id}", method=RequestMethod.GET)
      public String listNotes(@PathVariable int id,Model model) {
          Person person = personService.getCurrentlyAuthenticatedUser();
          this.setSectionid(id);
          model.addAttribute("person", new Person());
          model.addAttribute("listPersons", this.personService.listPersons());
         model.addAttribute("listNotes",this.notesService.listNotesBySectionId(id,person));
          return "note";
      }
  
  @RequestMapping(value= "/note/add")
      public String addNote(@ModelAttribute("notices") Notes p,Model model) {
          Person person = personService.getCurrentlyAuthenticatedUser();
          model.addAttribute("listNotes",this.notesService.listNotes());
  
          int id = getSectionid();
          System.out.println("Section id is"+id);
           model.addAttribute("listNotes",this.notesService.listNotesBySectionId(id,person));
          this.notesService.addNote(p, person);
          return "note";
      }
  </code></pre>
  
  <p>I tried looking up the net, but I don't know what it is called that I am looking for, so having a hard time. Any help would be good. Thank you. </p>