title: Spring Boot Rest Service | Request method 'GET' not supported
body: <p>I have made a hello world rest service using spring boot.
  I am able to call the service via standalone java program. I am also able to call it via <a href="https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US" rel="noreferrer">Advanced Rest Client</a> add-on for Chrome.</p>
  
  <p>But when I try to hit it via a standalone HTML page using jQuery AJAX I am getting error</p>
  
  <blockquote>
    <p>WARN 3748 --- [nio-9000-exec-2] o.s.web.servlet.PageNotFound             : Request method 'GET' not supported</p>
  </blockquote>
  
  <p>Any Help is appreciated.</p>
  
  <blockquote>
    <p>PS: I am assuming that as I am able to call the WebService using other
    modes so the controller is fine. But something is wrong the way I am
    calling it from the HTML.</p>
  </blockquote>
  
  <p><strong>HTML Page Below:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;meta charset="ISO-8859-1"&gt;
    &lt;title&gt;Client&lt;/title&gt;
    &lt;script type="text/javascript" src="jquery-2.2.3.js"&gt;
    &lt;/script&gt;
    &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
        $("#Submit").click(function() {
          var input = {
            "name": $("#name").val(),
            "language": $("#language").val()
          };
          var inputStr = JSON.stringify(input);
          alert(inputStr);
          $.ajax({
            url: "http://localhost:9000/rest/greetMeObj/",
            method: "POST",
            data: inputStr,
            dataType: "jsonp",
            success: function(output) { // callback method for further manipulations
              var str = JSON.stringify(output);
              $("#output").text(data);
            },
            error: function(data) { // if error occured
              $("#error").text(data);
            }
          });
  
        });
      });
    &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;div id="input"&gt;
      &lt;label&gt;&lt;b&gt;Name:&lt;/b&gt;
      &lt;/label&gt;
      &lt;input type="text" name="name" id="name" alt="Enter you name" title="Enter your name" /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;label&gt;&lt;b&gt;Language:&lt;/b&gt;
      &lt;/label&gt;
      &lt;select name="language" id="language" title="Select your language"&gt;
        &lt;option value="en" label="English" selected="selected"&gt;English&lt;/option&gt;
        &lt;option value="fr" label="French"&gt;French&lt;/option&gt;
        &lt;option value="nl" label="Dutch"&gt;Dutch&lt;/option&gt;
      &lt;/select&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;button title="Submit" type="button" name="Submit" id="Submit" value="Submit" formaction="POST"&gt;Submit&lt;/button&gt;
    &lt;/div&gt;
    &lt;div id="output"&gt;&lt;/div&gt;
    &lt;div id="error" style="color: red;"&gt;&lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Spring Controller Below</strong></p>
  
  <pre><code>@Controller
  @RequestMapping("/rest/*")
  public class GreetingController {
  
      private static final String TEMPLATE_EN = "Hello, %s!";
      private static final String TEMPLATE_FR = "Bonjour, %s!";
      private static final String TEMPLATE_NL = "Hallo, %s!";
      private final AtomicLong counter = new AtomicLong();
  
      @RequestMapping(value="/rest/greetMe", method= RequestMethod.GET)
      public @ResponseBody Greeting sayHello(
              @RequestParam(value = "name", required = false, defaultValue = "Stranger") String name,
              @RequestParam(value = "language", required = false, defaultValue = "en") String language) {
          return new Greeting(counter.incrementAndGet(), String.format(getTemplate(language), name));
      }
  
      @RequestMapping(value="/rest/greetMeObj", method= RequestMethod.POST)
      public @ResponseBody Greeting sayHello(
              @RequestBody(required = true) Input input) {
          return new Greeting(counter.incrementAndGet(),
                  String.format(getTemplate(input.getLanguage()), input.getName()));
      }
  
      private String getTemplate(String language) {
          String template;
          switch (language) {
          case "nl":
          case "NL":
              template = TEMPLATE_NL;
              break;
          case "fr":
          case "FR":
              template = TEMPLATE_FR;
              break;
          case "en":
          case "EN":
          default:
              template = TEMPLATE_EN;
              break;
          }
          return template;
      }
  }
  </code></pre>