Spring MVC RESTFul Service POST Data Complete example

Spring MVC RESTFul Service POST Data Complete example

In this tutorial you will see how to develop Spring MVC RESTFul service and post data through HTML page and also test it through Postman – REST client for chrome efficient way to test RESTFul Service. Here we will post data with two value name and another string value with multiple line and process it. Please follow steps below:

  • Create maven project name: SpringMVCRESTFulService
  • Final project structure:

Spring MVC RESTFul Service POST Data Complete example

  • pom.xml:

  • web.xml:

  • dispatcher-servlet.xml

  • index.jsp:

SpringMVCController.java: In this class I will show you how to process form request data using below two method parameter:

  • @RequestBody: We will process form data using @RequestBody. Here all request comes as one object which is whole form request and data will be seperated by name value pair as (name=Java Honk&stringValue=Post data test. Also you will see if request send as multiple line in string how to fetch each line from it.
  • @RequestParam:  We will process form data using @RequestBody. Here request will come as separate form field parameter and will be process separately.

Java Class:

  • We will use tomcat server to run this code. Once you download and configure project test data as below:

Spring MVC RESTFul Service POST Data Complete example

  • As you see above we have two form on JSP page to test data using two different way.  Click submit button separately you will see below output:

Spring MVC RESTFul Service POST Data Complete example

Spring MVC RESTFul Service POST Data Complete example

  • Now test this service using Postman – REST client for chrome. You could add this extension in your chrome browser and open your Postman rest client and enter data as below:

Spring MVC RESTFul Service POST Data Complete example

download Download Project: SpringMVCRESTFulService

Leave a Reply

Your email address will not be published. Required fields are marked *