Spring MVC Form Tags

Learn how to use Spring MVC form tags, which provide automatic data binding.

HTML forms are used to get input from the user. Spring MVC provides form tags which support data binding. These tags automatically set and retrieve data of a bean.

Examples of form tags include <form:form>, <form:input>, <form:checkbox>,<form:radiobutton, and <form:select> etc. The taglib reference of the Spring Tag Library is needed on the JSP page to use the above mentioned form tags.

<%@ taglib prefix="form" uri= "http://www.springframework.org/tags/form" %>

To demonstrate the use of Spring MVC form tags, we will create a form add-player-form, where the user will enter information about a player. When the form is submitted, the user will be directed to a confirmation page, player-confirmation, which will echo the data entered in the add-player-form.

To keep the code for Spring MVC form tags separate, we will not use the already created Player class but create a new Athlete class in the io.datajek.springmvc package.

Initially, this class will have just one field, lastName, along with getter and setter methods and a no-argument constructor.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.