我正在尝试设置 content-disposition 标头以响应 servlet,但我在浏览器中收到此错误。我应该怎么办?
从服务器收到重复的标头
来自服务器的响应包含重复的标头。此问题通常是由于网站或代理配置错误造成的。只有网站或代理管理员可以解决此问题。
错误 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION):收到多个不同的 Content-Disposition 标头。不允许这样做以防止 HTTP 响应拆分攻击。
这是我的servlet控制器:
@RequestMapping("/**/paymentOrderReport.pdf")
public class PaymentOrderReportViewController extends org.springframework.web.servlet.mvc.AbstractController {
private PaymentDao paymentDao;
private JasperPdfView pdfView;
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=" + "report.pdf");
PaymentOrderEntity paymentOrderEntity = null;
String traceCode = request.getParameter(ParamConstants.TRACE_CODE);
if (traceCode != null) {
PaymentSheetRequestEntity payRequestEntity = paymentDao.loadByUniqueProperty(PaymentSheetRequestEntity.PROP_TRACE_CODE,
traceCode);
if (payRequestEntity != null) {
paymentOrderEntity = payRequestEntity.getPaymentOrder();
}
}
if (paymentOrderEntity != null) {
List<PaymentOrderEntity> result = new ArrayList<PaymentOrderEntity>();
result.add(paymentOrderEntity);
JRDataSource jrDataSource = new JRBeanCollectionDataSource(result);
Map<String, Object> model = new HashMap<String, Object>();
model.put("reportData", jrDataSource);
return new ModelAndView(pdfView, model);
}
return null;
}
public void setPaymentDao(PaymentDao paymentDao) {
this.paymentDao = paymentDao;
}
public void setPdfView(JasperPdfView pdfView) {
this.pdfView = pdfView;
}
}
和 JasperPdfView 类:
public class JasperPdfView extends AbstractJasperReportsView {
@Override
protected void renderReport(JasperPrint populatedReport, Map<String, Object> model, HttpServletResponse response) throws Exception {
JRPdfExporter jrPdfExporter = new JRPdfExporter();
if (getConvertedExporterParameters() != null) {
jrPdfExporter.setParameters(getConvertedExporterParameters());
}
jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, populatedReport);
jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
jrPdfExporter.exportReport();
}
}