Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Spring MVC - Capture and Display the Data from Registration Form
Next article icon

Spring MVC - Capture and Display the Data from Registration Form

Last Updated : 30 May, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

This article is the continuation of this article Spring MVC - Create Registration Form using Form Tag Library, where we have successfully created a registration form using the Form Tag Library. Here in this article, we are going to explain how can we capture the data that are entered by the user and display it on our next page after clicking the Register button. A sample image is given below to get an idea about what we are going to do in this article. 

Spring MVC - Capture and Display the Data from Registration Form
 

Implementation

Add Code in the registration-page.jsp file

Go to the registration-page.jsp file and add the below line of code inside the form:form tag. 

<form:form action="registration-complete" method="get" modelAttribute="userRegInfo">

All other things remain unchanged. 

File: Updated registration-page.jsp

HTML
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>  <html> <body>      <h1 align="center">Create Registration Form using Form Tag in Spring MVC</h1>                <!-- Changes in this line -->     <form:form action="registration-complete" method="get" modelAttribute="userRegInfo">           <div align="center">          <!-- A Simple Input Field -->     <label>Name : </label>     <form:input path="name"/>          <br/>          <label>User Name : </label>     <form:input path="userName"/>          <br/>          <label>Password : </label>     <form:password path="password"/>          <br/>          <!-- DropDown Field -->     <label>Branch : </label>     <form:select path="branch">         <form:option value="CSE" label="Computer Science"></form:option>         <form:option value="CSA" label="Computer Science and Application"></form:option>         <form:option value="EE" label="Electrical Engineering"></form:option>         <form:option value="ME" label="Mechanical Engineering"></form:option>     </form:select>          <br/>          <!-- CheckBox Field -->     <label>Skills : </label>     Java : <form:checkbox path="skills" value="java"/>     Python : <form:checkbox path="skills" value="python"/>     C++ : <form:checkbox path="skills" value="cpp"/>     DSA : <form:checkbox path="skills" value="dsa"/>     Spring : <form:checkbox path="skills" value="spring"/>          <br/>          <!-- RadioButton Field -->     <label>Gender : </label>     Male<form:radiobutton path="gender" value="male"/>     Female<form:radiobutton path="gender" value="female"/>          <br/>          <!-- Button Field -->     <input type="submit" value="Register">          </div>          </form:form>  </body> </html> 

Add Code in RegistrationController.java File

Now again come to the RegistrationController.java file and create another method something like this with the "registration-complete" endpoint because we have mentioned the same inside the form:form tag as an action. 

@RequestMapping("/registration-complete") public String processUserReg(@ModelAttribute("userRegInfo") UserRegistrationDTO userRegistrationDTO) {         return "registration-complete"; }

File: Updated RegistrationController.java

Java
package com.geeksforgeeks.calculator.controllers;  import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping;  import com.geeksforgeeks.calculator.dto.UserRegistrationDTO;  @Controller public class RegistrationController {      @RequestMapping("/register")     public String showRegistrationPage(@ModelAttribute("userRegInfo") UserRegistrationDTO userRegistrationDTO) {         return "registration-page";     }      @RequestMapping("/registration-complete")     public String processUserReg(@ModelAttribute("userRegInfo") UserRegistrationDTO userRegistrationDTO) {         return "registration-complete";     }  } 

Create a New View

In the next step, we have to create a new view named "registration-complete" inside the WEB-INF > view folder. And below is the code for the registration-complete.jsp file.

HTML
<html> <head> </head> <body>      <h1 align="center">Registration Successful</h1>     <h2>The details entered by the user are :</h2>            Name:         ${userRegInfo.name}     <br/>         User Name:  ${userRegInfo.userName} <br/>         Password:   ${userRegInfo.password} <br/>         Branch:     ${userRegInfo.branch}   <br/>         Skills:     ${userRegInfo.skills}   <br/>         Gender:     ${userRegInfo.gender}   <br/>  </body> </html> 

So we are done with the coding. Now, let's run our application again and test if things are working fine or not. 

Output

Hit the following URL to run your controller

http://localhost:8080/simple-calculator/geeksforgeeks.org/register

Output:

 

Let's fill the form,

 

Then click on the "Register" button and you can see all the details that are entered by the user have been displayed successfully.

 

Next Article
Spring MVC - Capture and Display the Data from Registration Form

A

AmiyaRanjanRout
Improve
Article Tags :
  • Java
  • Java-Spring
  • Java-Spring-MVC
Practice Tags :
  • Java

Similar Reads

    Spring MVC JSTL Configuration
    JavaServer Pages Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. Here we will be discussing how to use the Maven build tool to add JSTL support to a Spring MVC application. also, you'll learn how to act
    1 min read
    Spring MVC with MySQL - Sample Project For Calculating Electricity Bill
    Let us see a sample electricity bill calculation project by using Spring MVC + MySQL connectivity + JDBCTemplate. Additionally, let us test the same by using MockMvc + JUnit. MySQL Queries: DROP DATABASE IF EXISTS test; CREATE DATABASE test; USE test; DROP TABLE test.personsdetails; CREATE TABLE per
    7 min read
    Spring MVC - Comparison of Cryptocurrencies using REST API
    REST APIS is available in plenty nowadays. As cryptocurrencies are a hot topic nowadays, there is always a need to compare the different cryptocurrencies and get the corresponding value in different currencies. As a sample, let us take a REST API call as https://min-api.cryptocompare.com/data/price?
    6 min read
    Spring MVC - Get Probability of a Gender by Providing a Name using REST API
    A lot of funful REST API calls are available as open source. Suppose if we like to keep a name to our nears and dears, we can just check that by means of a REST API call and get the gender, what is the probability of being that gender and how many times does it come with it? Relevant REST API call h
    7 min read
    Get Time Zone by Providing Latitude and Longitude using Spring MVC and REST API
    Spring MVC Framework follows the Model-View-Controller design pattern. It is used to develop web applications. It works around DispatcherServlet. DispatcherServlet handles all the HTTP requests and responses. In this article, we are going to see about a REST API call to find the coordinates for the
    6 min read
    Spring MVC with MySQL and Junit - Finding Employees Based on Location
    In real-world scenarios, organizations are existing in different localities. Employees are available in many locations. Sometimes they work in different 2 locations i.e. for a few days, they work on location 1 and for a few other days, they work on location 2. Let's simulate this scenario via MySQL
    8 min read
    Spring MVC - Get University/College Details via REST API
    REpresentational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services. REST API is a way of accessing web services in a simple and flexible way without having any processing. Spring MVC is a Web MVC Framework for building web applicat
    6 min read
    Spring MVC - JSTL forEach Tag with Example
    JSP Standard Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. JSTL aims to provide an easy way to maintain SP pages The use of tags defined in JSTL has Simplified the task of the designers to create Web
    6 min read
    Spring MVC - Iterating List on JSP using JSTL
    JSP Standard Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. JSTL aims to provide an easy way to maintain SP pages The use of tags defined in JSTL has Simplified the task of the designers to create Web
    6 min read
    Two-Way Data Binding in Spring MVC with Example
    Data Binding, as the name itself, is a self-explanatory word. In data binding what we have to do is we have to capture or store the data so that we can bind that data with another resource (for example displaying the data in the frontend part) as per our needs or we can also read the data from a var
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences