douxiuyi6529 2016-09-26 06:19
浏览 770

Ajax调用URL无法在Spring服务器上找到@RequestMapping值

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

  • 写回答

1条回答 默认 最新

  • dongzhuo1733 2016-09-26 06:51
    关注

    Annotate your controller class with @RestController and also return something in the method.

    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题