简体   繁体   English

错误 http 400 与 java 和 servlets、Z2D7FCA4F5778E7194B40B46062

[英]ERROR http 400 with java and servlets, JSP

How about community, this error happened to me today and I would like to know if some of you ever happened to you and how to solve it.社区怎么样,这个错误今天发生在我身上,我想知道你们中的一些人是否曾经发生过以及如何解决它。 I am creating an application with servlets in java that the functionality is to have a button, where by clicking it sends me a json with 50 records through the URL so that I can generate an excel. I am creating an application with servlets in java that the functionality is to have a button, where by clicking it sends me a json with 50 records through the URL so that I can generate an excel. Now, all good when it comes to 10 records, no problem happens, when you have more than 20 records in that json or so, that's where the error happens to me.现在,当涉及到 10 条记录时,一切都很好,没有问题发生,当您在 json 左右有超过 20 条记录时,这就是我发生错误的地方。 Investigating I found that the error happens because the header I am sending is too long.调查我发现错误发生是因为我发送的 header 太长了。 Here is an example of what the header I'm sending is:这是我发送的 header 的示例:

Url: localhost:8080/pruebas/vistas/excel/Reporte_Insertados.jsp?registros=[{"CODPER":"123456","NRO":"1","DNI":"45874587","APELLIDOS_NOMBRES":"ROJAS%20LOPEZ%20GUSTAVO","FECHA":"14/01/2020","MONTO":"150.50","OBSERVACION":"DADSADSA","RAZON_SOCIAL":"","ESTADO":"DATOS%20CORRECTOS","":""}...] so until you have 50 records.

So my question is: If any of you solve it or how could I do it from my servlet to allow the header to be long, since it is the problem for which it does not leave me and the error happens to me.所以我的问题是:如果你们中的任何人解决了它,或者我怎么能从我的 servlet 中做到这一点,以允许 header 很长,因为它不会离开我并且错误发生在我身上。 I leave code of my application.我留下我的应用程序的代码。 Thank you in advance community.提前感谢社区。

My Javascript code:
function exportarReporteInsertados(registrosInsertados){
let tabla_reporte_insertados = $("#tablaCargaMasiva").tableToJSON({});//Here grab all 50 records.
window.location = "excel/Reporte_Insertados.jsp?registros="+JSON.stringify(tabla_reporte_insertados)
}

My jsp code to receive the data我的 jsp 代码接收数据

    <%@page import="org.json.JSONObject"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="org.json.JSONArray"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    String datos = request.getParameter("registros");

    JSONArray jsonArray_datos = new JSONArray(datos);

%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "attachment; filename=REPORTE_CARGA_MASIVA.xls");

         %>

ERROR enter image description here错误在此处输入图像描述

@Felipo If you need to send a json, kindly refrain from adding it to the url. @Felipo 如果您需要发送 json,请不要将其添加到 url。 The url string has a character limit.Please look at: What is apache's maximum url length? url 字符串有字符限制。请看: apache 的最大 url 长度是多少? . . Also, according to convention in order to send a json via the request you need to add it to the request body instead of the url.此外,按照惯例,为了通过请求发送json ,您需要将其添加到请求正文而不是 url。 Use an ajax request to send the data to the endpoint instead of passing it via the url.使用 ajax 请求将数据发送到端点,而不是通过 url 传递数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM