In this lesson, we will set up a form, which will prompt the user to enter a player’s name. When the user clicks the "Submit" button, our Spring MVC application will show a page containing the name entered by the user. Later, we will add functionality to show details of the player entered by the user.

A controller can have multiple request mappings. We will add methods to the TennisPlayerController to handle different request mappings. We will map the URL showPlayerForm to a method that displays the form and processPlayerForm to a method that directs the user to the player details page.

Controller method to show the form

The TennisPlayerController class is shown below. It is annotated with @Controller which tells Spring that this class will handle web requests.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.