title: Pass parameter to Spring controller using @PathVariable
body: <p>I have a jsp that has an input field and a button. I should pass the input value to controller. My controller calls a REST API and get the response. Here the controller works fine.</p>
  
  <p>search-menu.jsp</p>
  
  <pre><code>  &lt;input  id="txt-menu-search" name="txt-menu-search" type="text"
                          class="form-control input-sm"/&gt;
  
              &lt;button class="btn btn-primary input-sm" id="btn-menu-search"&gt;&lt;span&gt;&lt;i
                      class="glyphicon glyphicon-search"&gt;&lt;/i&gt;&lt;/span&gt;&lt;/button&gt;
  </code></pre>
  
  <p>SearchMenuController.java</p>
  
  <pre><code>@RequestMapping(value = "/search-menu/{searchItem}", method = RequestMethod.GET)
  
  public ModelAndView generateSearchItem(@PathVariable String searchItem ) {
      ModelAndView modelAndView = new ModelAndView("search-results");
      // modelAndView.addObject("searchItem", searchItem);
      RestTemplate restTemplate = new RestTemplate();
      String getItemUrl = SendStringBuilds.sendString(baseUrl, searchItemNameUrl, searchItem);
  
      ServerResponseMessage searchItemResponse = restTemplate.getForObject(getItemUrl, ServerResponseMessage.class);
      modelAndView.addObject("it", searchItemResponse.getData());
      modelAndView.addObject("test", searchItem);
      return modelAndView;
  }
  </code></pre>
  
  <p>This controller works when I change the URL. But it does not get the input value for path variable.
  The Ajax in the search-menu.jsp is as follows.</p>
  
  <pre><code>&lt;script&gt;
      $("#btn-menu-search").click(function () {
          var searchKey = $("#txt-menu-search").val();
          $.ajax({
              type: 'GET',
              url: '/web-selfcare/search-menu/'+searchKey,
              success: function (result) {
          }
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Tell me how to map the input to the controller.</p>