I am implementing form handling. I have a form page student.jsp where the user is required to fill in the details.
I have a POJO class for that. Then I have a formOutput.jsp which displays the user details.
Here is the code for my controller
My code is working fine. Can anyone please tell me what is the role of "@ModelAttribute("SpringWeb")Student student" parameter in addStudent method.
@ModelAttribute is used to direclty set the values in the Student object from the jsp, other wise in the servlet you have to get the properties using request.getattribute() and than call student setter method.
There is an implicit model even if you do not pass one in. This Model is used by spring to store information needed to render the view. A model is just a glorified Map. A ModelAttribute is stored in the model under the name you give or using convention if a name is not provided. In your case you have a Person, that means that if a Person object exists in the Model under the key "SpringWeb" (would make more sense to name it "person" here. It will be retrieved and passed into your method. If it does not exist a new Person object will be created automatically and put in the model. You can than access it directly in your jsp (you would get rid of command)