Ajax帖子在Spring中出现404错误

时间:2018-06-17 10:26:28

标签: ajax spring jsp

我正在从jsp overlay页面对控制器进行ajax调用。调用控制器,但浏览器抛出404错误页面。我希望控件位于叠加页面

jsp页面摘录:

            <s:form action="expressEOI" class="form-horizontal" method="POST"
                        enctype="multipart/form-data" modelAttribute="expressEOIBean">
                        <div class="form-group"></div>

             ........

            <button class="btn btn-info" name="eoiSavebtn" id="eoiSavebtn">Please
                                        Save </button>


        $(document).ready(function() {
        .....
        $('#eoiSavebtn').attr('onClick','javascript:saveEOI("'+contextPath+'","'+ applicationId+'")');

ajax电话:

            $.ajax({
                    type : "POST",
                    url :  window.location.protocol + "//"+ window.location.host + contextPath+ "/saveEOI",
                    cache : false,
                    data: {'applicationId' : applicationId},

                    success : function(e) { alert("success");   },

                    error : function(e) { }
                });

控制器:

@RequestMapping(value = "/saveEOI", method = RequestMethod.POST)
    public String saveEOI(HttpSession session, HttpServletResponse response,
            HttpServletRequest request) {
        if (logger.isDebugEnabled()) {
            logger.debug("ExpressEOIController :: Save EOI() : Start");
        }
.....

1 个答案:

答案 0 :(得分:0)

首先尝试逐步调试应用程序

postman,curl或任何其他休息客户端尝试使用有效负载主体作为空JSON进行后调用。如果这也返回404,则它是服务器问题。如果成功或抛出任何java错误然后我们知道它是UI问题。另外,请务必将内容类型标题添加为'application/json'

这将有助于隔离问题