Announcement Announcement Module
Collapse
No announcement yet.
Post Method Not Supported Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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)

      Comment


      • #4
        Thanks for this this resolved my issue.

        Comment

        Working...
        X