Announcement Announcement Module
No announcement yet.
Getting error when submitting form using SpringMVC and REST Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting error when submitting form using SpringMVC and REST

    Hello there,

    Created an online form in JSP using SpringMVC tag libraries. The controller for my form is a RESTful web service.

    The RESTful web service has two calls:

    (1) http://localhost:8080/myapp/applications/new

    This brings up the online form in the browser (this works).

    (2) http://localhost:8080/myapp/applications/create

    This saves the form data to a database (handles submit). This is where it breaks.

    Followed the conventions from the sample demo petclinic app which comes with the Spring Framework.

    Online form:

    <%@ page contentType="text/html;charset=UTF-8" language="java"%>
    <%@ taglib prefix="c" uri=""%>
    <%@ taglib prefix="spring" uri=""%>
    <%@ taglib prefix="form" uri="" %>
    <form:form modelAttribute="application" method="POST" action="create">
    	  <td><form:input path="name" size="30" maxlength="80"/></td>
    	  <td><form:input path="description" size="30" maxlength="80"/></td>
    	  <td>Image URL:</td>
    	  <td><form:input path="imgUrl" size="30" maxlength="80"/></td>
    	<input type="submit" value="Save" />
    The RESTful web service which serves as form controller:

    public class ApplicationsResource
    	private final Logger log = LoggerFactory.getLogger(ApplicationsResource.class);
    	public static final String APPLICATION_URL = "/applications";
    	private ApplicationManager applicationManager;
    	public void getNewApplication(@Context HttpServletRequest request, @ModelAttribute Application app)
    	{"ApplicationsResource - Inside getNewApplication() method.");
    		String contentType = request.getContentType();"Content-Type:" + contentType);
    			if ("POST".equalsIgnoreCase(request.getMethod()))
    				if (app != null)
    				{;"Added application: " + app.getName());
    				{"Application not added");
    		catch (Exception e)
    		{"Exception: ", e);
    			throw new WebApplicationException(Response.status(RestError.SERVER_ERROR_HTTP_RESP).type("application/json;charset=utf-8").entity(new ErrorOutput(RestError.SERVER_ERROR_CODE, RestError.SERVER_ERROR_MSG, e.toString())).build());
    	public void setAllowedFields(WebDataBinder dataBinder)
    		dataBinder.setDisallowedFields(new String[] {"id"});
    	@Produces( { MediaType.TEXT_HTML })
    	public ModelAndView getNewApplicationForm()
    	{"ApplicationsResource - Inside getNewApplicationForm");
    		ModelAndView mv = new ModelAndView("/applications/applications_new");
    		mv.addObject("application", new Application());
    		return mv;
    Exception thrown when I click on submit:

    Failed executing POST /applications/create
    org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class com.myapp.domain.Application of content type: application/x-www-form-urlencoded
    	at org.jboss.resteasy.core.MessageBodyParameterInjector$1.createReaderNotFound(
    	at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(
    	at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(
    	at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(
    	at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(
    Does anyone know why I am getting this exception?

    Would really appreciate it if someone could help me with this issue...

    Happy programming and thank you for taking the time to read this.
    Last edited by socal_javaguy; Oct 15th, 2009, 09:08 PM. Reason: grammer

  • #2

    Found the solution!

    It was a RESTEasy problem... The fix was putting the @Form Application App inside the parameter list and prepending the domain model object's setters with @FormParam("name").

    See: Integrating RESTEasy with SpringMVC