I've created a JSP page that includes some JavaScript code:
function sendData(tableID) {
var table = document.getElementById(tableID);
var dataArray= new Array();
for (var i = 1;i<table.rows.length; i++){
var row = table.rows[i];
for (var j = 0; j < row.cells.length; j++){
alert("Added to array: "+row.cells[j].getElementsByTagName('INPUT')[0].value);
dataArray.push(row.cells[j].getElementsByTagName('INPUT')[0].value);
}
}
var ajaxRequest;
try{
// Creating XMLHttpRequest object
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Handling older versions of Internet Explorer
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser doesn't support AJAX!");
return false;
}
}
}
// Sending POST request to 'proyecto/saveRecompensas' URL
ajaxRequest.open('POST', 'proyecto/saveRecompensas');
ajaxRequest.send('dataArray='+dataArray);
}
I also have a Controller with a method designed to handle the request along with the array data sent from the JavaScript function:
@RequestMapping ("/proyecto/saveRecompensas")
public String saveData(@RequestParam String[] dataArray){
System.out.println("saveData method");
return null;
}
The problem lies in the fact that the sysout statement within the method is not being executed. Consequently, when the JavaScript function runs, the server console displays the following warning message:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/myapp/proyecto/proyecto/saveRecompensas] in DispatcherServlet with name 'appServlet'
It appears there is an issue with the URI having double "proyecto". How should I structure the URL for the server to properly receive the request? Am I correctly sending the parameters?
Thank you.
EDIT:
Here's my Dispatcher configuration:
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>