[英]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.