带有Spring MVC的ajax中的BadRequest错误

时间:2016-10-08 07:00:50

标签: ajax spring-mvc http-status-code-400

我正在尝试向我的控制器发送请求,每当我点击提交按钮时,它都会出现错误请求错误。 我无法找出代码有什么问题。

回到Home.jsp

<div id="setReminder">
                    <label class="generalReminder" style="text-decoration: none;">General
                        Reminder</label>
                    <table>
                        <tr>
                            <td>Date</td>
                            <td><input type="text" readonly="readonly"
                                id="birthdayDate"></td>
                        </tr>
                        <tr>
                            <td>Time</td>
                            <td><input type="text" readonly="readonly" id="callTime"
                                ></td>
                        </tr>
                        <tr>
                            <td>Message</td>
                            <td><textarea id="reminderTag" rows="5"></textarea></td>
                        </tr>
                    </table>
                </div>
                <div id="reminderDot" style="margin-top: 24%; position: relative;">
                    <button class="submitReminder" onclick="saveReminderDetails();">Submit</button>
                </div>

Home.js

function saveReminderDetails(){
var x="";
x=scheduleBirthdayReminder();
if(x){
    $.ajax({
        type:"POST",
        url:"submitBirthdayRequest.do",
        data : {
            birthdayDate :$("#birthdayDate").val(),
            birthdayTime : $("#callTime").val(),
            birthdayReminder : $("#reminderTag").val()
        },
        success : function(data) {
            alert('data is'+data);
            $("#birthdayDate").val('');
            $("#callTime").val('');
            $("#reminderTag").val('');
        }
    });
}

 }

Controller.java

@RequestMapping(value="submitBirthdayRequest.do",method=RequestMethod.POST)
public @ResponseBody String submitSchedulerDetails(@RequestParam("birthdayDate")String birthdayDate,@RequestParam("callTime")String birthdayTime,@RequestParam("reminderTag")String reminderTag,HttpServletRequest request ){
    System.out.println("adding reminder details with birthdayDate "+birthdayDate+"and time"+birthdayTime);
    String userIdentity=((UserDetails)request.getSession(false).getAttribute("loginDetails")).getName();
    try{
        boolean schedulerObj= schedulerService.addSchedulerBirthdayDetails(userIdentity,birthdayDate, birthdayTime,reminderTag);    
    }catch(Exception e){
        e.printStackTrace();
    }
    return birthdayTime;

}

错误

http://localhost:8083/Testing/submitBirthdayRequest.do 400 (Bad Request)

1 个答案:

答案 0 :(得分:1)

请求中的参数名称与预期值不匹配。尝试更改

Dockerfile

或更改客户端的参数名称