I'm a beginner with using Ajax Call and Spring server. I wanted to send some JSON format data from html to the Spring server. Here is my Ajax Call code:
function sendToServer(){
$.ajax({
type: "POST",
url:"/maricobalagi/getJsonByMap",
dataType: "json",
data:"{formdata}",
//success and error message
success: function() {
alert("The page has been successfully loaded");
},
error: function() {
alert("An error occurred");
},
});
}
But i have an issue with the Ajax Call URL, it couldn't find the "/getJsonByMap"
value. There is an error message "POST http://localhost:8092/maricobalagi/getJsonByMap 404 (Not Found)"
in the console log. And here is my server code:
public class Controller{
@RequestMapping(value = "/getJsonByMap" , method = RequestMethod.POST)
public @ResponseBody Map post(@RequestBody final Map JSONmap){
//myCode
}
}
i just have web.xml, here is my web.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Generic</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
And here is my project folder: Project Folder Screenshot