title: Populate form using values getting from Spring Controller
body: <p>I am simply creating a CRUD Application in Spring MVC. I want to edit Student Details. I have created one form which is used to add student. How can I use the same form to populate the student details for editing it ?</p>
  
  <p>Controller</p>
  
  <pre><code>@RequestMapping(value="/add", method = RequestMethod.GET)
  public String addStudent(@RequestParam("studentName") String name,@RequestParam("studentId") String studId){
      System.out.println("Student Id : "+ studId);
      System.out.println("Student "+name+" added");
      list.add(name);
      return "redirect:get";
  }
  
  @RequestMapping(value="/edit/${index}", method = RequestMethod.GET)
  public String editStudent(@PathVariable("index") int index, Model model){
      System.out.println("Edit Student with Index " + index);
      model.addAttribute("studentId",index);
      model.addAttribute("studentName",list.get(index));
      return "student";
  }
  </code></pre>
  
  <p>Form</p>
  
  <pre><code>&lt;c:url value="/students/add" var="addStudentAction"&gt;&lt;/c:url&gt;
  &lt;form action="${addStudentAction}" method="get"&gt;
      &lt;input type="hidden" name="studentId"&gt;
      &lt;input type="text" name="studentName"&gt;&lt;/input&gt;
      &lt;input type="submit" name="submit" value="Add Student" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I want to set studentId and studentName in form fields which are set in model in editStudent method.</p>