下面的代码90%的时间工作在正常长度的JSON字符串上。我在我的SpringMVC控制器中接收到一个传入的JSON字符串,它是由一个DataTable .data()
形成的。
Ajax:
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");
}
主计长:
@RequestMapping(value="/loadParticipantsExportValues", method=RequestMethod.POST)
public void loadParticipantsExportValues(@RequestParam("participants") String json) throws Exception {
//...
}
但是,在非常大的JSON字符串上(由10K行DataTable形成),即使我在调试器中验证是否创建了数组,我还是得到了如下结果:
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'participants' is not present
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:204)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:112)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
有什么想法吗?什么东西是被截断了还是最大限度地消失了?
发布于 2019-10-21 21:46:52
我解决了。这是Tomcat maxPostSize
问题,默认值是2MB。
修复它的例子,server.xml in Tomcat
<Connector port="8009" maxPostSize="4000000" protocol="AJP/1.3" redirectPort="8443"/>
或者,无限的:
<Connector port="8009" maxPostSize="-1" protocol="AJP/1.3" redirectPort="8443"/>
发布于 2019-10-21 16:50:56
许多客户端截断大请求参数-> limit on query String
请使用@RequestBody
,如
@RequestMapping(value="/loadParticipantsExportValues", method=RequestMethod.POST)
public void loadParticipantsExportValues(@RequestBody String participants) throws Exception{
//....
}
https://stackoverflow.com/questions/58490346
复制相似问题