Home » Spring MVC Form Text Field

Spring MVC Form Text Field

by Online Tutorials Library

Spring MVC Form Text Field

The Spring MVC form text field tag generates an HTML input tag using the bound value. By default, the type of the input tag is text.

Syntax

Here, path attribute binds the form field to the bean property.

The Spring MVC form tag library also provides other input types such as email, date, tel, etc.

For email:

For date:


Example of Spring MVC Form Text Field

Let’s see an example to create a railway reservation form using form tag library.

1. Add dependencies to pom.xml file.

2. Create the bean class

Here, the bean class contains the variables (along setter and getter methods) corresponding to the input field exist in the form.

Reservation.java

3. Create the controller class

ReservationController.java

4. Provide the entry of controller in the web.xml file

web.xml

5. Define the bean in the xml file

spring-servlet.xml

6. Create the requested page

index.jsp

7. Create other view components

reservation-page.jsp

Note – The value passed with the @ModelAttribute annotation should be the same to the modelAttribute value present in the view page.

confirmation-page.jsp

Output:

Spring MVC Form Text Field
Spring MVC Form Text Field
Spring MVC Form Text Field
Spring MVC Form Text Field

Next TopicForm Radio Button

You may also like