I need to send an array from my JSP page to a Spring Controller. In my JSP I get my array full with the things I need, and then, I start an AJAX request:
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.open('POST', 'saveRecompensas.action');
ajaxRequest.send('array='+array);
In the Controller:
@RequestMapping ("/proyecto/saveRecompensas")
public String saveRecompensas(@RequestParam ("array") String[] array, HttpSession session){
//public String saveRecompensas(){
System.out.println(Method saveRecompensas called");
return null;
}
As you can see, I have two methods signature. That is because, if I use the one without the @RequestParam ("array") String[] array, the method is called ok. But I need that array. If I use with the RequestParam, the method is never called.
Is this the correct way to send and array from JSP to Controller? What Im doing wrong? Thank you.