1
對於我的應用程序,我正在編寫POST請求以從複選框列表中發送參數數組。它的工作獲取請求,但不適用於發佈請求。我的代碼中有什麼錯誤。java spring boot HTTP POST請求不起作用
我的代碼在客戶端發送ajax請求到服務器。
$(".add").click(function(){
monitoring.length=0;
nonMonitoring.length=0;
$('.modal-body input:checked').each(function() {
monitoring.push($(this).val());
});
$('.addkeywords input:checked').each(function() {
nonMonitoring.push($(this).val());
});
// alert(monitoring[2]+ " " + nonMonitoring[2]);
var monitoringLength=monitoring.length;
var nonMonitoringLength=nonMonitoring.length;
$.ajax({
type : "POST",
url : '/rest/channelstats/my/rest/controller',
data : {
// monitoring : monitoring,
// nonMonitoring: nonMonitoring,
monitoringLength: monitoringLength,
nonMonitoringLength: nonMonitoringLength,
},
success : function(data) {
// var keywordsList=data
//console.log(keywordsList);
// htm = "" ;
}
});
})
我在服務器端的java代碼。
@RequestMapping(value="/rest/channelstats/my/rest/controller",method = RequestMethod.POST)
public void monitorKeywords(@RequestParam(value="monitoringLength",required=true)int monitoringLength,@RequestParam(value="nonMonitoringLength",required=true)int nonMonitoringLength){
System.out.println("MonitoringLength =>" +monitoringLength);
System.out.println("NonMonitoringLength=>" +nonMonitoringLength);
}
}
它爲HTTP GET請求工作,但不適用於POST請求。如何解決此問題?
什麼是你所得到的錯誤? – Karthik
它不顯示任何錯誤,它不打印輸出在服務器端的控制檯 –
? – Karthik