How pass an array javascript in the data of ajax that call a servlet

Viewed 35

My problem it's that I define an ajax request to a servlet, and send in the ajax request a javascript array of Object defined in js. In java I have also a bean Class with same name e method. How can I read this array in java servlet? Because

This is my js (I want to send String, and one array of IngQua object):

var list= [];
---fill list---
$.ajax({
    type: "POST",
    url: "/insert",
    data: {
        title:title,
        description:description,
        prep:prep,
        list:list,
        advice:advice
    },  
    success: function(res){
        if(res === "OK")
            alert("OK");
    },
    error: function(xhr){
        
    }
})

While this is my servlet

@PostMapping("/insert")
@ResponseBody
public String insert(@RequestParam("title") String titolo, @RequestParam("description") String description, 
        @RequestParam("prep")String prep,@RequestParam("advice") String advice, ,
     @RequestParam("list") ArrayList<IngQua> list, HttpServletRequest req ) {
    System.out.println(titolo);
    return "OK";
    
}

And this is the exception:

Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'list' for method parameter type ArrayList is not present]
0 Answers
Related