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 8542707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:07:54+00:00 2026-06-11T12:07:54+00:00

I have been stuck on this problem for a very long time. I have

  • 0

I have been stuck on this problem for a very long time. I have looked on resources on the Internet but cannot find where I am going wrong. I have configured Spring MVC to send and receive JSON. When I invoke a RESTful service from the web browser for @ResponseBody the Object that is being returned is returned as JSON. However, when trying to invoke a @RequestBody I am unable to.

Below is the code:

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
     <display-name>WebApp</display-name>

     <context-param>
        <!-- Specifies the list of Spring Configuration files in comma     separated format.-->
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/history-service.xml</param-value>
     </context-param>

     <listener>
        <!-- Loads your Configuration Files-->
        <listener-    class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>

     <servlet>
        <servlet-name>history</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet-mapping>
        <servlet-name>history</servlet-name>
        <url-pattern>/</url-pattern>
     </servlet-mapping>

     <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>    

history-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans>     
    <context:component-scan base-package="com.web"/>

    <mvc:annotation-driven/>

    <context:annotation-config/>

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

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

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

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json"/>
            </map>
        </property>
    </bean>-->  

Controller class

   @Controller
   @RequestMapping("/history/*")
   public class ControllerI {

@RequestMapping(value = "save", method = RequestMethod.POST, headers = {"content-            type=application/json"})
public @ResponseBody UserResponse save(@RequestBody User user) throws Exception {
    UserResponse userResponse = new UserResponse();
    return userResponse;
}

@RequestMapping(value = "delete", method = RequestMethod.GET)
public @ResponseBody UserResponse delete() {
    System.out.println("Delete");
    UserResponse userResponse = new UserResponse();
    userResponse.setSuccess(true);
    return userResponse;
}

When invoking /webapp/history/delete I can receive JSON.

Index.jsp

    <%@page language="java" contentType="text/html"%>
 <html>
 <head>
 </head>
 <body>
 <h2>WebApp</h2>
<form action="/webapp/history/save" method="POST" accept="application/json">
    <input name="userId" value="Hello">
    <input name="location" value="location">
    <input name="emailAddress" value="hello@hello.com">
    <input name="commitMessage" value="I">
    <input type="submit" value="Submit">
</form>
</body>
</html>

However, when invoking the /save I get the following error:

org.springframework.web.servlet.mvc.support.DefaultHandlerE
xceptionResolver handleNoSuchRequestHandlingMethod
WARNING: No matching handler method found for servlet request: path '/history/sa
ve', method 'POST', parameters map['location' -> array<String>['location'], 'use
rId' -> array<String>['Hello'], 'emailAddress' -> array<String>['hello@hello.com'], 'commitMessage' -> array<String>['I']]

I am not sure where I am going wrong. All I want to do is send JSON through JSP to the Spring MVC Controller so the @RequestBody can be turned deserialized into Java from JSON.

I hope you can help.

  • 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-06-11T12:07:55+00:00Added an answer on June 11, 2026 at 12:07 pm

    chage accept=”application/json” to enctype=”application/json” on your HTML form.

    Spring can not parse you post data for you did not set the current headers.
    When use @RequestBody the default accept enctype is application/json.
    try to one of this:

    1. set post headers=”content-type=application/json” on you html form or js post function.
    2. set you controller to accept headers=”content-type=application/x-www-form-urlencoded”.

    Edit

    The enctype must the same as headers.
    Ok, the code now looks like one of those:

    // the one
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public @ResponseBody UserResponse save(@RequestBody User user) throws Exception {
        UserResponse userResponse = new UserResponse();
        return userResponse;
    }
    
    
    </form>
    <form action="/webapp/history/save" method="POST" enctype="application/x-www-form-urlencoded">
        <input name="userId" value="user">
        <input name="location" value="location">
        <input name="emailAddress" value="hello@hello.com">
        <input name="commitMessage" value="I">
        <input type="submit" value="Submit">
    </form>
    
    
    // the other
    @RequestMapping(value = "save", method = RequestMethod.POST, headers = {"content-type=application/x-www-form-urlencoded"})
    public @ResponseBody UserResponse save(@RequestBody User user) throws Exception {
        UserResponse userResponse = new UserResponse();
        return userResponse;
    }
    
    
    </form>
    <form action="/webapp/history/save" method="POST" enctype="application/json">
        <input name="userId" value="user">
        <input name="location" value="location">
        <input name="emailAddress" value="hello@hello.com">
        <input name="commitMessage" value="I">
        <input type="submit" value="Submit">
    </form>
    

    Try one of those above.

    I get the following error:

    HTTP Error 415: The server refused this request because the request
    entity is in a format not supported by the requested resource for the
    requested method ().

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

Sidebar

Related Questions

I have been stuck for a long time on this simple but obtuse message
I've been stuck on this likely very simple problem, but haven't gotten anywhere with
I'm new to android and have been stuck on this problem for a long
I'm very new to AS3 and I have been stuck with this problem for
Hope to get solution to this problem. I have been stuck on it since
I have been stuck on this for a while now and I cannot seem
I have been stuck on this silly if statement, whatever i do, I cannot
I have now been stuck at this for some time so I though to
i know this is basic but somehow i have been stuck here for some
I have been stuck on this problem for a while now. I want to

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.