Announcement Announcement Module
No announcement yet.
Help submitting HTML form via SpringMVC and RESTful Web Service Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help submitting HTML form via SpringMVC and RESTful Web Service

    Hello there,

    I am created an online form using SpringMVC tag library (as a JSP file) and also a Controller (think Model View Controller pattern) as a RESTful Web Service.

    When I deploy and invoke the web service by doing this in the browser:


    Am able to view the SpringMVC based form (in Firefox) but when I enter in information and click on Submit, it displays the following:

    HTTP Status 404 - /application/new
    type Status report
    message /application/new
    description The requested resource (/application/new) is not available.
    The RESTful Web Service (Controller):

    public class ApplicationResource
    	private final Logger log = LoggerFactory.getLogger(ApplicationResource.class);
    	public static final String APPLICATION_URL = "/applications";
    	private ApplicationManager applicationManager;
    	public ModelAndView getNewApplication(@Context HttpServletRequest request)
    		log.debug("Inside getNewApplication() method.");
    		ModelAndView modelAndView = new ModelAndView("/applications/applications_new");
    		String message = "";
    			if ("POST".equalsIgnoreCase(request.getMethod()))
    				String name = request.getParameter("name");
    				String description = request.getParameter("description");
    				String imgUrl = request.getParameter("imgUrl");
    				Application app = new Application();
    				if (app != null)
    					message = "Added application: " + app.getName();
    					message = "Invalid";
    				modelAndView.addObject("message", message);
    		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());
    		return modelAndView;
    	@Produces({ MediaType.TEXT_HTML})
    	public ModelAndView getNewApplicationForm()
    		ModelAndView mv = new ModelAndView("/applications/applications_new");
    		mv.addObject("application", new Application());
    		log.debug("Inside getNewApplicationForm");
    		return mv;
    applications_new.jsp (Here's the view (which does launch when I invoke it)):

    <%@ page contentType="text/html;charset=UTF-8" language="java"%>
    <%@ taglib prefix="c" uri=""%>
    <%@ taglib prefix="spring" uri=""%>
    <%@ taglib prefix="form" uri="" %>
    <form:form commandName="application" method="POST" action="/application/new">
    	  <td><form:input path="name"/></td>
    	  <td><form:input path="description" /></td>
    	  <td>Image URL:</td>
    	  <td><form:input path="imgUrl" /></td>
    	<input type="submit" value="submit" />
    What could I be possibly be doing wrong?

    Thank you for taking the time to read this...

  • #2
    It's issues like this that make me wish there was a BeanPostProcessor that would scan for all @Path annotations and print out the resulting URL segments. It would be a good review of what you've declared, and comparing that against what you're trying to call would be enlightening.

    In this case, I believe you're declaring the root of your URL to be "/applications/...", but you're trying to call "/application/...".