最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - String exceeding ajax POST length limit - Stack Overflow

programmeradmin7浏览0评论

I'm trying to send an array from my jsp to my Servlet via ajax POST request. My array has a few objects with many fields. If I try to send and array with 11 objects - using JSON.stringify - it works OK (the array is received on server-side), but the problem happens when I try to send an array with 12+ objects. The error is: 400 Bad Request and looking with Google Chrome Debugger, I can find this error: fluxos:(unable to decode value) where fluxos is the name of my array.

RELEVANTE PART OF CODE:

for(var i=0; i<numberOfConnections; i++) {
    fluxo = criaEstruturaFluxo(i);
    fluxos.push(fluxo);
}

$.ajax({
    type: "POST", 
    url: 'Servlet?fluxos='+JSON.stringify(fluxos),
            success: function (data) {
            alert('success');
    }
});

...
function criaEstruturaFluxo(i) {
    ...
    ...
    var fluxo = {
      xOrigem: xOrigem, 
      yOrigem: yOrigem,
      xDestino: xDestino,
      yDestino: yDestino,
      codWorkflow: codWorkflow,
      acaoAvanco: acaoAvanco,
      codAtividadeOrigem: codAtividadeOrigem[1],
      codAtividadeDestino: codAtividadeDestino[1],
      numero: numero,
      nomeAtividadeOrigem: nomeAtividadeOrigem,
      nomeAtividadeDestino: nomeAtividadeDestino,
      codConexao: codConexao,
      tipoOrigem: tipoOrigem,
      tipoDestino: tipoDestino,
      xFluxoOrigem: xFluxoOrigem,
      yFluxoOrigem: yFluxoOrigem,
      xFluxoDestino: xFluxoDestino,
      yFluxoDestino: yFluxoDestino,
      deletarArquivo: deletarArquivo,
      ultimaConexao: ultimaConexao,
      caminhoArquivo: caminhoArquivo,
      xTela: xTela,
      yTela: yTela
    };

    return fluxo;
}

My encoded array has 8000+ characters length and because of that, I think it's exceeding the max length a POST request can handle... Is that possible or might be something on the code that I'm sending to my Servlet?

I'm trying to send an array from my jsp to my Servlet via ajax POST request. My array has a few objects with many fields. If I try to send and array with 11 objects - using JSON.stringify - it works OK (the array is received on server-side), but the problem happens when I try to send an array with 12+ objects. The error is: 400 Bad Request and looking with Google Chrome Debugger, I can find this error: fluxos:(unable to decode value) where fluxos is the name of my array.

RELEVANTE PART OF CODE:

for(var i=0; i<numberOfConnections; i++) {
    fluxo = criaEstruturaFluxo(i);
    fluxos.push(fluxo);
}

$.ajax({
    type: "POST", 
    url: 'Servlet?fluxos='+JSON.stringify(fluxos),
            success: function (data) {
            alert('success');
    }
});

...
function criaEstruturaFluxo(i) {
    ...
    ...
    var fluxo = {
      xOrigem: xOrigem, 
      yOrigem: yOrigem,
      xDestino: xDestino,
      yDestino: yDestino,
      codWorkflow: codWorkflow,
      acaoAvanco: acaoAvanco,
      codAtividadeOrigem: codAtividadeOrigem[1],
      codAtividadeDestino: codAtividadeDestino[1],
      numero: numero,
      nomeAtividadeOrigem: nomeAtividadeOrigem,
      nomeAtividadeDestino: nomeAtividadeDestino,
      codConexao: codConexao,
      tipoOrigem: tipoOrigem,
      tipoDestino: tipoDestino,
      xFluxoOrigem: xFluxoOrigem,
      yFluxoOrigem: yFluxoOrigem,
      xFluxoDestino: xFluxoDestino,
      yFluxoDestino: yFluxoDestino,
      deletarArquivo: deletarArquivo,
      ultimaConexao: ultimaConexao,
      caminhoArquivo: caminhoArquivo,
      xTela: xTela,
      yTela: yTela
    };

    return fluxo;
}

My encoded array has 8000+ characters length and because of that, I think it's exceeding the max length a POST request can handle... Is that possible or might be something on the code that I'm sending to my Servlet?

Share Improve this question asked Apr 29, 2014 at 20:42 lucasdclucasdc 1,0422 gold badges20 silver badges43 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Your url is very long. In theory that shouldn't cause any problems, but there's a practical limit that depends on the server and proxies that you use. Send the data on the body of the request and not on the url.

Agree with Andres & Luiggi. Here's what your modified code would look like:

$.ajax({
url: "Servlet",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "fluxos": fluxos }),
success: function(data) {
    alert("success");
}

});

发布评论

评论列表(0)

  1. 暂无评论