Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7040571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:56:03+00:00 2026-05-28T01:56:03+00:00

Iam bit new to SpringMVC REST concept. Need a help from experts here to

  • 0

Iam bit new to SpringMVC REST concept. Need a help from experts here to understand/ resolve following issue,
I have developed a SpringMVC application, following is a part of a controller class code, and it works perfectly ok with the way it is, meaning it works ok with the JSON type object,

@RequestMapping(method = RequestMethod.POST, value = "/user/register")
public ModelAndView addUser( @RequestBody String payload) {

    try{

        ObjectMapper mapper = new ObjectMapper();
        CreateNewUserRequest request = mapper.readValue(payload, CreateNewUserRequest.class);

        UserBusiness userBusiness = UserBusinessImpl.getInstance();
        CreateNewUserResponse response = userBusiness.createNewUser(request);


        return new ModelAndView(ControllerConstant.JASON_VIEW_RESOLVER, "RESPONSE", response);

and this is my rest-servlet.xml looks like

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

<bean id="jsonViewResolver" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" />


<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jsonConverter" />
        </list>
    </property>
</bean>

<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes" value="application/json" />
</bean> 

<bean name="UserController" class="com.tap.mvp.controller.UserController"/>

My problem is how do i make it work for normal POST request, My controller should not accept JSON type object instead it should work for normal HTTP POST variables.
How do i get values from the request?What are the modifications should i need to be done for that. I need to get rid of

ObjectMapper mapper = new ObjectMapper();
        CreateNewUserRequest request = mapper.readValue(payload, CreateNewUserRequest.class);

and instead need to add way to create an instance of

CreateNewUserRequest

class, by invoking its constructor. For that i need to get values from request. How do i do that? Can i treat @RequestBody String payload as a map and get the values? or is there a specific way to get values from the request of HTTP POST method? following values will be in the request,

firstName, lastName, email,password

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:56:04+00:00Added an answer on May 28, 2026 at 1:56 am

    You are mixing two concepts here. The REST service in Spring MVC is much more elegant as Spring handles JSON/XML marshalling for you:

    @RequestMapping(
          headers = {"content-type=application/json"},
          method = RequestMethod.POST, value = "/user/register")
    @ResponseBody
    public CreateNewUserResponse addUser( @RequestBody CreateNewUserRequest request) {
            UserBusiness userBusiness = UserBusinessImpl.getInstance();
            return userBusiness.createNewUser(request);
    }
    

    Notice the @ResponseBody annotation. You don’t need any view resolvers and manual JSON marshalling. And you get XML (via JAXB) for free.

    However data sent via form POST is very different. I would suggest creating second mapping handling different media type:

    @RequestMapping(
          headers = {"content-type=application/x-www-form-urlencoded"},
          method = RequestMethod.POST, value = "/user/register")
    public ModelAndView addUser(@RequestParam("formParam1") String formParam1) {
      //...
    }
    

    With this configuration REST calls with Content-type=application/json will be routed to first method and form POST requests to the second one (at least in theory, haven’t tried it). Note that there are simpler ways to handle form data in Spring compared to raw @RequestParam annotation, see: Pass a request parameter in Spring MVC 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a bit new to sql and php so I need some help
I am a bit new to Perl and I need some help regarding moving
I am a bit new to Perl, but here is what I want to
I am a bit new to LINQ, here is my problem. I have a
I am a bit new to javascript and was trying to understand how the
I am lil bit new to objective C. Here is my requirement. I have
I am a bit new to php and I need to create a quiz
i am a bit new to using jquery, the following should display a button,
I am a bit new to VB - So hopefully you can help me.
I am a bit new to Android. What I need to do is send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.