How it works...

The simple form controller contains only one URL mapping and it is confined at the class-level @RequestMapping annotation. It only consists of two handler methods: the initForm(), which is the GET handler method, and the submitForm(), the POST handler. Request handlers such as initForm() prepare the form view for form loading, while the submitForm() processes all the incoming request data, validates them against form rules, and generates the needed response by forwarding all results to the success view.

The usual way of retrieving request parameters is to use the getParameter() method of HttpServletRequest, but the only problem here is when the number of request data increases, which makes validation and type-checking difficult to manage. Spring devised an organized way of managing request data and that is to store it in a model object such as the EmployeeForm. Using the Spring Form tag library, we bind all the parameter data to the properties of the POJO model through the modelAttribute of the <form:form> tag. After clicking the submit button, this model object is passed on to the submitForm() in the form of an object parameter using the @ModelAttribute annotation. These model objects are synonymous to the term form backing objects. Depending on the intention, the submitForm() either calls its own success_page or just redirects to the form_page, especially when form validation is implemented to avoid SQL injection and Denial of Attack (DoA) problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.33.235