Results 1 to 4 of 4

Thread: Post Method Not Supported

  1. #1
    Join Date
    Jun 2007
    Posts
    16

    Default Post Method Not Supported

    Hi
    I have whats probably a very simple issue but not sure what I'm doing wrong I have added a method to a controller based on the RSVP tutorial. Its like this:
    Code:
        @RequestMapping(method = RequestMethod.POST)
        public String post(@ModelAttribute("AppUser") AppUser appUser, ModelMap modelMap) {
        	if (appUser.getId() == null) {
        		appUser.persist();
            	if (appUser.getEmail().length() > 0) {
            		sendMessage("a valid email address", "SoccerScene Account has been created", appUser.getEmail(), "Thanks for joining the site your username is " + appUser.getUsername() + ".");
            	}
        	} else {
        		appUser.merge();
        	}
        	return "thanks";
        }
    For some reason this just does not work when trying to create a user I get the following stack trace:
    Code:
    2010-07-16 21:23:48,241 [http-8080-6] DEBUG org.springframework.web.servlet.DispatcherServlet - Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'uncaughtException'; model is {exception=org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported}
    org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.resolveHandlerMethod(AnnotationMethodHandlerAdapter.java:600)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:416)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    Any ideas is there some security setting I am missing?
    Thanks

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    Without seeing the complete app it is hard to determine what exactly is going wrong here. My guess would be that you will need to create an explicit mapping for the request here:


    Code:
    @RequestMapping(value = "/foo", method = RequestMethod.POST)
    So this would then map to http://<server-name>:<port>/<app-name>/<controller>/foo

    If you don't explicitly specify the mapping Spring will automatically use the method name as mapping:

    http://<server-name>:<port>/<app-name>/<controller>/post

    Are you using this as URL in your form post?

    -Stefan
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  3. #3
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    18

    Default

    Quote Originally Posted by davidhay View Post
    Hi
    I have whats probably a very simple issue but not sure what I'm doing wrong I have added a method to a controller based on the RSVP tutorial. Its like this:
    Code:
        @RequestMapping(method = RequestMethod.POST)
        public String post(@ModelAttribute("AppUser") AppUser appUser, ModelMap modelMap) {
        	if (appUser.getId() == null) {
        		appUser.persist();
            	if (appUser.getEmail().length() > 0) {
            		sendMessage("a valid email address", "SoccerScene Account has been created", appUser.getEmail(), "Thanks for joining the site your username is " + appUser.getUsername() + ".");
            	}
        	} else {
        		appUser.merge();
        	}
        	return "thanks";
        }
    For some reason this just does not work when trying to create a user I get the following stack trace:
    Code:
    2010-07-16 21:23:48,241 [http-8080-6] DEBUG org.springframework.web.servlet.DispatcherServlet - Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'uncaughtException'; model is {exception=org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported}
    org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.resolveHandlerMethod(AnnotationMethodHandlerAdapter.java:600)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:416)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    Any ideas is there some security setting I am missing?
    Thanks
    I had faced the same issue before but now it's working fine. Please try this below.

    @RequestMapping(value = "/{pathURL}", method = RequestMethod.POST)
    public String post(@ModelAttribute("AppUser") AppUser appUser, ModelMap modelMap,@PathVariable String pathURL)


    @RequestMapping(value = "/{pathURL}", method = RequestMethod.GET)
    public String get(ModelMap modelMap,@PathVariable String pathURL)
    ORLANDO

  4. #4
    Join Date
    Jun 2007
    Posts
    16

    Default

    Thanks for this this resolved my issue.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •