Model

Learn how to pass data between controllers and views.

In a Spring MVC application, the Model manages data. It serves as a container for carrying data between different components of the application. When the Controller retrieves data from sources like databases, web services, or Spring beans, it places this data into the Model. The View template can access this data to display it to the client. The Model acts as the intermediary for transporting data between the various parts of the application.


In this lesson, we will first pass the Model to our Controller class, then add some data to it and finally show how the data in the Model is accessed in the View page.

Press + to interact
Passing data from Controller to View template
Passing data from Controller to View template

We have created a form in search-player-form.jsp that takes a player name as input. The code for the form is reproduced below:

Press + to interact
<form action="processPlayerForm" method="GET">
Enter player name:
<input type="text" name="playerName" placeholder="Enter player name"/>
<input type="submit" value="Submit" />
</form>

When "Submit" is clicked, a GET request invokes the processForm() method of the TennisPlayerController ...

Access this course and 1400+ top-rated courses and projects.