title: Spring Exception: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
body: <p>I have a ResponseEntiy that receives a comment:</p>
  
  <pre><code>@RequestMapping(value="/save-comment", method=RequestMethod.POST)
  @ResponseBody
  public ResponseEntity&lt;?&gt; saveComment(@RequestParam("name") String comment, @RequestParam("id") long id) {
  
      SiteUser user = authController.getUser();
  
      String cleanedCommentBody = htmlPolicy.sanitize(comment);
  
      StatusUpdate status = statusUpdateService.getOneById(id);
  
      Comment createdcomment = new Comment();
      createdcomment.setCommentdate(new Date());
      createdcomment.setCommenttext(cleanedCommentBody);
      createdcomment.setStatusUpdate(status);
      createdcomment.setSiteUser(user);
  
      commentService.createComment(createdcomment);
  
      return new ResponseEntity&lt;&gt;(null, HttpStatus.OK);
  }
  </code></pre>
  
  <p>The code in my JSP works fine.... it sends the values to my Controller method and the method receives it, process the information and saves the new comment in the database, but after that, showing the same page.... <strong>it gives me the error. But other POST request I have work fine.</strong></p>
  
  <pre><code>http://192.168.160.128:8080/viewonestatus/58 
  Exception: org.springframework.web.HttpRequestMethodNotSupportedException: 
  Request method 'POST' not supported
  Failed URL: http://192.168.160.128:8080/viewonestatus/58
  Exception message: Request method 'POST' not supported
  </code></pre>
  
  <p>The AJAX snippet is that gives an ok code is:</p>
  
  <pre><code>.....
  &lt;c:url var="saveComment" value="/save-comment" /&gt;
  .....
  
  function saveComment(text) {
      //alert("El texto es...text " + text);
      editComment(text, "${status.id}", "${saveComment}");
  }
  
  function editComment(text, id, actionUrl) {
  
      var token = $("meta[name='_csrf']").attr("content");
      var header = $("meta[name='_csrf_header']").attr("content");
  
      $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
          jqXHR.setRequestHeader(header, token);
      });
  
      $.ajax({
          'url' : actionUrl,
  
          data : {
              'name' : text,
              'id' : id
          },
  
          type : 'POST',
  
          success : function() {
              alert("Ok");
          },
  
          error : function() {
              alert("error");
          }
      });
  }
  </code></pre>