We have previously discussed the Spring MVC form tags. The form tag library provides a variety of form tags that are used to build web applications. One of them is a <form:input> tag used to generate text field.

<form:input> – It represents an HTML input tag used to develop text fields using bound values.

The following code snippet shows how to use the <form:input> tag:

Let’s briefly understand the concept of <form:input> tag with the help of an example.

Example of MVC Form Text Field

Here, we are going to create an example of a form text field using <form:input> tag.

Following are the steps to create an example of a form text field:

  • Create a request page

In this step, we are going to create a request page named index.jsp.

index.jsp

  • Create the Model class

In this step, we are going to create the Model class named Student.java, which stores the field values.  

Student.java

  • Create the Controller

In this step, we are going to create a Controller class named StudentController.java, which returns the JSP pages.

StudentController.java

  • Add the entry of Controller in web.xml

In this step, we are going to add the entry of the Controller inside the web.xml file.

web.xml

  • Define the Model in another XML file

In this step, we are going to define the Model class in another XML file (spring-servlet.xml).

spring-servlet.xml

  • Create all the view pages

In this step, we are going to create all the view pages (JSP pages) required in the application.

studentform.jsp

student-data.jsp

Output

Spring MVC Form Text Field
Spring MVC Form Text Field 1
Spring MVC Form Text Field 2
Spring MVC Form Text Field 3

Pin It on Pinterest

Share This