"Welcome To Ashok IT" "Spring Boot and MicroServices" Topic : Spring MVC - Form Submission Date : 12/05/2025 (Session - 44) _____________________________________________________________________________________________________________________________ Yesterday Session ================= * We completed development for First Spring MVC Application. Today Session ============= We Will see how to send the data to the Request Processor Method ================================================================= * Inorder to send the data from client to Server we have multiple sources 1) Adding key-value pairs to the browser Request URL ==================================================== http://localhost:8080/27_SpringMVC_App/welcome >>>>>>>>>>>>> Sending Blank Request to Server without having any data http://localhost:8080/27_SpringMVC_App/welcome?username=mahesh >>>>> Sending Request to Server with One Parameter. http -------> Protocal localhost -----> Current Machine 8080 --------> portno 27_SpringMVC_App ----------> WebApplication Name welcome--------> URL Pattern username=mahesh -----------> Request Parameters(username(key),mahesh(value)) http://localhost:8080/27_SpringMVC_App/welcome?username=mahesh&city=Hyderabad >>>>> Sending Request to Server with Multiple Parameters. ?username=mahesh&city=Hyderabad >>>>>>>> QueryString(Request parameters) RequestParameter Names : username,city RequestParameter Values : mahesh,Hyderabad Reading the Request Parameters in the RequestProcessor method of Controller class ================================================================================= 1) Gathering All Request Parameters into Map Object by using annotation called @RequestParam. public String processLogin(@Requestparam Map requestParams) { } 2) Gathering the Request Parameter independently public String processLogin(@RequestParam("username") String uname, @RequestParam("city") String cityName){ } Problems ======= 1) It is not recommended for sending data via URL because its not good practise sending sensitive information in URL. 2) It is not enduser friendly approach. 2) Sending Data to Server using Html Forms ========================================== * As programmer we need to send one Html form to the user browser. * User has to fill the form with proper data and submit that form. * Onces form got submitted by the user the data of form will sent to Server as Request Parameters(or) Request Body Example Application =================== * We will develop two Request Processor methods 1) Request processor method is for rendering the Html Form i.e., welcome page. 2) Request Processor method is for processing the Html Form Data. enquiry.jsp =========== <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> registration.jsp
Welcome To AshokIT For Spring MVC Application Development...
Name
EmailID
ContactNo
Course
confirmation.jsp ================ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> confirmation.jsp
Student Name : ${enquiryInfo.firstName}
Course Name : ${enquiryInfo.courses}
Your Enquiry is Received for above Details Admin Team will connect with you shortly.....
EnquiryController.java ====================== package com.ashokit.controller; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller public class EnquiryController { @RequestMapping("/") public ModelAndView getEnquiryPage() { return new ModelAndView("enquiry"); } @RequestMapping(value="sendEnquiry",method = RequestMethod.POST) public ModelAndView processEnquiryDetails(@RequestParam Map formData) { ModelAndView mav = new ModelAndView("confirmation"); mav.addObject("enquiryInfo", formData); return mav; } } web.xml ======= AshokITFormSubmission ashokit org.springframework.web.servlet.DispatcherServlet 1 ashokit / ashokit-servlet.xml =================== pom.xml ======= 4.0.0 com.ashokit 29_SpringMVC_FormSubmission_App 0.0.1-SNAPSHOT war UTF-8 17 17 org.springframework spring-webmvc 6.0.11 jakarta.servlet jakarta.servlet-api 5.0.0 provided OUTPUT ====== Request URL : http://localhost:1234/29_SpringMVC_FormSubmission_App/ Will load the enquiry form into browser Fill the form with required details and submit form Acknowlege Message ================== StudentName : Mahesh StudentName : SpringBoot Your Enquiry is Received for above Details Admin Team will connect with you shortly..... Assignment =========== * Completeing the Same Application and test this application form method as "get". * Observe the Request URL in the Browser URL Bar...