簡體   English   中英

錯誤 http 400 與 java 和 servlets、Z2D7FCA4F5778E7194B40B46062

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

社區怎么樣,這個錯誤今天發生在我身上,我想知道你們中的一些人是否曾經發生過以及如何解決它。 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. 現在,當涉及到 10 條記錄時,一切都很好,沒有問題發生,當您在 json 左右有超過 20 條記錄時,這就是我發生錯誤的地方。 調查我發現錯誤發生是因為我發送的 header 太長了。 這是我發送的 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.

所以我的問題是:如果你們中的任何人解決了它,或者我怎么能從我的 servlet 中做到這一點,以允許 header 很長,因為它不會離開我並且錯誤發生在我身上。 我留下我的應用程序的代碼。 提前感謝社區。

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)
}

我的 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");

         %>

錯誤在此處輸入圖像描述

@Felipo 如果您需要發送 json,請不要將其添加到 url。 url 字符串有字符限制。請看: apache 的最大 url 長度是多少? . 此外,按照慣例,為了通過請求發送json ,您需要將其添加到請求正文而不是 url。 使用 ajax 請求將數據發送到端點,而不是通過 url 傳遞數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM