How to pass data from <form:select> Spring MVC

前端 未结 1 1929
说谎
说谎 2020-12-10 14:17

I would like to share my problem with you.

I built on jsp page and use on my page some of it use to

相关标签:
1条回答
  • 2020-12-10 15:07

    I believe you should use <form:select> inside the <form:form>.

    It should look like this:

    search.jsp:

    <form:form modelAttribute="myform" action="result" method="get" >
      <form:select  path="nameOfInstitution">
        <form:option value="NONE"> --SELECT--</form:option>
        <form:options items="${listOfInstitutionsNames}"></form:options>
      </form:select>
      ...
    </form:form>
    

    HomeController.java:

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public String search(Model model) {
      ...
      model.addAttribute("myform", new MyForm());
      return "search";
    }
    
    @RequestMapping(value = "/result", method = RequestMethod.GET)
    public String SecondActionPage(@RequestParam String nameOfInstitution,
        Model model,
        @ModelAttribute("myform") MyForm myform)
        throws Exception {
      ...
    }
    

    MyForm.java:

    public class MyForm {
      private String nameOfInstitution;
    
      public String getNameOfInstitution() {
        return nameOfInstitution;
      }
    
      public void setNameOfInstitution(String nameOfInstitution) {
        this.nameOfInstitution = nameOfInstitution;
      }
    }
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题