title: How to call controller method from jsp using ajax
body: <p>I am using spring boot, maven 3.2.5.
  I am working on simple maven webapp using spring boot following mvc  pattern.
  i am trying to call controller method from jsp suing ajax.</p>
  
  <p>this is my jsp javascript method look like , which call the ajax call to call the controller method.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function listExistingUser()
   { 
   
   alert("listExistingUser");
  
    $.ajax({
     type : "GET",
     url : '${home}/loginController/listExistingUser',
     dataType : "json",
        crossDomain:true,
     success : function(data) {
      //console.log(data);
      //alert(data.toString());
      checkValidUser(data); 
     },
     error : function(data) {
       
     }
     });
   } </code></pre>
  </div>
  </div>
  </p>
  
  <p>Bellow is my controller class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@Controller
  @RequestMapping("/loginController")
  public class LoginController {
   
   @Autowired
   LoginService loginService;
   
   @RequestMapping(value = "/listExistingUser", method = RequestMethod.GET)
    @ResponseBody
   public Object getAuthentication(@ModelAttribute("studentId") int studentId,
        HttpServletRequest request, HttpServletResponse response)
        {
      System.out.println("listExistingUser is called in controller");
        }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>when I run my application, I am able to access login.jsp from the bellow url
  <code>http://localhost:9090/seperation-management/pages/login.jsp</code></p>
  
  <p>when i hit submit button my jsp page javascript method is also getting called that is <code>alert("listExistingUser");</code>
  but i am not able to called my controller method.</p>
  
  <p>where I am making mistake. can anyone help me.</p>