Spring MVC Post Form Submit AJAX jQuery

Spring MVC Post Form Submit AJAX jQuery

In this tutorial you will see how to post form data submit using AJAX and jQuery in Spring MVC application. We will process response from the server and shows data on alert message.

  • Download project from below and import to eclipse as maven projec
  • Below is final project struecture

Spring MVC Post Form Submit AJAX jQuery

  • SumbitForm.jsp:

  • Users.java:

  • SpringMVCController.java:

  • For this demo we have run this project on tomcat 7.0 below is output:

Spring MVC Post Form Submit AJAX jQuerySpring MVC Post Form Submit AJAX jQuery

Spring MVC Post Form Submit AJAX jQuery

  • For more information about submit post data using jQuery and AJAX please use this link 

download  Download Project:  SpringMVCAJAXFormSubmit

11 thoughts on “Spring MVC Post Form Submit AJAX jQuery

  1. Hello sir,
    When I run this tutorial sample, I go this error
    please help sir
    The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().

  2. I got exactly the same annoying error : 415 Unsupported Media Type.
    But i have :


    and spring 4.1.7 (i upgrated in case)


    What is wrong?

  3. I’m very thanks for your exercise that can make me when i have problem. I hop that you upload new exercise soon. Many thank!

  4. This logic “Gathering the Data” works for text fields, but does not work for checkboxes. It always transfers the “value” of the checkbox element regardless whether the checkbox is checked or not.

    // Gather Data also remove undefined keys(buttons)
    $.each(this, function(i, v) {
    var input = $(v);

    if (input.attr(“type”) == “checkbox”)
    data[input.attr(“name”)] = input.checked ? true : false;
    data[input.attr(“name”)] = input.val();

    delete data[“undefined”];

  5. I am using knouckout js , ajax with html page with Spring framework. I am not able to send data from spring controller to html page. any comment on this ?

    • @RequestMapping(value = “/ajaxWsCustomerRegister”,method = RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE)
      public ModelAndView makeCustomerRegisterWebService(@RequestBody String json, HttpServletResponse response) throws IOException, ParseException{
      ObjectMapper mapper = new ObjectMapper();
      RegisterModel requestValue = mapper.readValue(json, RegisterModel.class);
      String email =requestValue.getEmail();
      String password = requestValue.getPassword();
      String arsnumber = requestValue.getArsnumber();
      String ssn = requestValue.getSsn();
      JSONObject inputJsonObject = new JSONObject();
      inputJsonObject.put(“arsnumber”, arsnumber);
      String result = postDataToWebservice(inputJsonObject,”register”);
      JSONParser jsonParser = new JSONParser();
      JSONObject customerSSNFromCUBS = (JSONObject) jsonParser.parse(result);
      String ssnFromCUBS = (String) customerSSNFromCUBS.get(“ssn”);
      ModelAndView modelAndView = new ModelAndView();
      System.out.println(“SSN matched-“+ssnFromCUBS);
      boolean isCustomerRegistered=customerDao.register(email,password,ssn,arsnumber);
      System.out.println(“Is Customer registered in db? “+isCustomerRegistered);
      modelAndView.addObject(“result”, “customer registered sucessfully”);
      modelAndView.addObject(“message”, “customer not registered due to DB”);
      System.out.println(“SSN expected-“+ssnFromCUBS+””+ssn);
      modelAndView.addObject(“message”, “incorrect ssn”);
      return modelAndView;

      i am using model and view but how java object bind with it.

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *