mercredi 25 février 2015

In MVC how is the data passed from JSP to Controller?

I'm following the Spring MVC tutorial here: http://ift.tt/1gSKMqZ and I'm not getting the logic how is the data passed from JSP to Controller.


I think I understand how the data is passed from the Controller to the JSP, but after the user has edited the form on the JSP how is the data passed to the Controller?


In the controller: public String addStudent(@ModelAttribute("SpringWeb")Student student, ModelMap model)



  1. question: How the controller knows that from the form on the jsp Student class instance student with name, age and id are passed?


I have this example working. I have altered the example to display a list of students, but I am not able to get the list from JSP to Controller:





@RequestMapping(value = "/student", method = RequestMethod.POST)
public ModelAndView studentSave(@ModelAttribute("listOfStudents") ArrayList<Student> listOfStudents,ModelMap model)
{
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

StudentJDBCTemplate studentJDBCTemplate = (StudentJDBCTemplate) context.getBean("studentJDBCTemplate");

System.out.println("Size of listOfStudents is = " + listOfStudents.size());
...



listOfStudents.size() returns 0.



  1. question: what am i missing here, why I can't get the list from the form on the jsp?


Thanks in advance for your help.


Aucun commentaire:

Enregistrer un commentaire