Using text, textarea, password, and hidden fields
In this recipe, you will learn how to display a text field, textarea field, password field, and hidden field using Spring form tags. When the form is submitted, we will retrieve the field value in a controller method.
How to do it…
Here are the steps to display and process text fields:
- If a default value is necessary, use a - Stringattribute of the default object (refer to the Setting a form's default values using a model object recipe):- user.setFirstName("Joe");
- In the JSP, use one of these Spring form tags: - <form:input path="firstName" /> <form:textarea path="firstName" /> <form:password path="firstName" /> <form:hidden path="firstName" /> 
- In the controller method processing the form submission, make sure that the - @ModelAttributeobject has a corresponding- Stringattribute:- public class User { private String firstName; ...
How it works…
The Spring form tag generates the HTML form field and populates it with the default value...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                