以下代码在正常长度的JSON字符串上有90%的时间可用。我在SpringMVC控制器中收到一个传入的JSON字符串,该字符串是由数据表@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
组成的。
Ajax:
.data()
控制器:
function exportParticipants() {
var table = $('#participantsTable').DataTable();
var displayData = table.rows({filter:'applied'}).data(); // Get my data into "result" array
var result = $.makeArray();
$.each(displayData,function(index,row) {
result.push(row);
});
$.ajax({
url: "/app/loadParticipantsExportValues",
type: "post",
data: {
'participants': JSON.stringify(result) // Note that I form this 'participants' param
},
success: function (res){
console.log("success");
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error");
}
但是仅在非常大的JSON字符串(由10K行DataTable形成)上,即使我在调试器中验证了数组已创建,我也得到了:
@RequestMapping(value="/loadParticipantsExportValues", method=RequestMethod.POST)
public void loadParticipantsExportValues(@RequestParam("participants") String json) throws Exception {
//...
}
有什么想法吗?是什么东西被截断或最大化?
答案 0 :(得分:2)
许多客户端截断大的Request参数-> limit on query String
请使用
中的@RequestBody
@RequestMapping(value="/loadParticipantsExportValues", method=RequestMethod.POST)
public void loadParticipantsExportValues(@RequestBody String participants) throws Exception{
//....
}
答案 1 :(得分:1)
我解决了。这是一个Tomcat maxPostSize
问题,默认值为2MB。
固定它的示例, Tomcat中的server.xml :
<Connector port="8009" maxPostSize="4000000" protocol="AJP/1.3" redirectPort="8443"/>
或无限:
<Connector port="8009" maxPostSize="-1" protocol="AJP/1.3" redirectPort="8443"/>