I'm trying to set content-disposition header in response of servlet, but i get this error in browser. What should i do?
Duplicate headers received from server
The response from the server contained duplicate headers. This problem is generally the result of a misconfigured website or proxy. Only the website or proxy administrator can fix this issue.
Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple distinct Content-Disposition headers received. This is disallowed to protect against HTTP response splitting attacks.
Here my servlet controller:
@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;
}
}
And JasperPdfView Class:
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();
}
}
Google Chrome might display this error message if you are downloading a file which has a comma in the file name. Were you really using just "report.pdf" as filename?
Having read the HTTP specs the Content-Disposition header (which is not part of the HTTP spec itself) should not include a comma character, because it will be treated as a separator for two different headers.
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.
So if your filename were report,May2014.pdf then Chrome interprets
Content-Disposition: attachment; filename=report,May2014.pdf
as two values for the same http message header
Content-Disposition: attachment; filename=report
Content-Disposition: May2014.pdf
which in turn is interpreted as a HTTP response splitting attack, probably because there shall actually be no multiple Content-Disposition header values in a single HTTP response.
Other browsers does not seem to mind the comma in the file name.
Incorrect:
response.setHeader("Content-Disposition","attachment;filename="+filename+);
Correct:
response.setHeader("Content-Disposition","attachment;filename=\""+filename+"\"");
There is a similar discussion here - http://productforums.google.com/forum/#!topic/chrome/hhZh_kpei8U
See if that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With