0% found this document useful (0 votes)
7 views

Spring Form Tag Library

Uploaded by

devaanirudh323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Spring Form Tag Library

Uploaded by

devaanirudh323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spring Form Tag Library :-

• It is a collection of JSP tags that simplify the process of creating HTML forms with Spring
MVC

Traditional Way

 Here we will be getting the values from the form using HttpServletRequest and
then creating the student obj and setting all those values and then adding it to
the model and we can retrive these values in first.jsp like this
<h2>${stdObj.getName()}</h2>

 But if we have many text fields in the form it would be very difficult to get all
those values and then create a object and again set all those values into that
object
□ So we can use Spring form Tag Library to solve this issue

Why we should use Spring Form Tag Library :-

1. Data Binding Support:


 The form tags help with data binding between form fields and Java Objects. This
means that values entered into the form fields can be automatically bound to
corresponding properties of Java Object
2. Validation Support:
 The form tag library integrates with the Spring Validation Framework or others
allowing us to perform server-side validations easily
3. Internationalization (i18n):
 The form tag library supports internationalization by providing tags that allow us
to display messages in different langauges based on the user location
4. Improved Code Reability:
 The tags make our code more readable and easier to maintain
5. Reduce Development Time:
 The tags help us to develop web applications more quickly and easily

• NOTE :
○ The Spring Form Tag Library is a powerful tool that can help us to develop web
applications more quickly and easily. It is a standard part of the Spring MVC
Framework and used by many developers
○ To use Spring Form Tag Library we have to add one dependency i.e. spring-security-
taglibs

Folder Structure
Since in form page we are Going get
Student details here we need to create
Student Obj and add it to model

Before sending the request to form page we created a


empty Student object and added it to model and after
the request went to the form page this Student Object
will be initialized with values and after initializing
since the request is redirecting to "/profile" here we
will be getting the Student object automatically with
values

This and this


should be same

Inorder to use the


form tag this line is
compulsory
@ModelAttribute :-
• It is an annotation that is used to bind a method parameters or return value to a model
attribute, facilatating data preparation for view or form handling
• How to use @ModelAttribute:-
a. Parameter-Level Annotation

○ Rather than using the left side part we can use right side part
 Both do the same task

a. Method-Level Annotation

You might also like