Specify the name of the Pdf file that will be transferred back to the browser

I have a Java webapp that creates a pdf file and transfers it back to the browser.

 byte[] pdf = report.exportPdfToArray(user);
response.setContentType("application/pdf");
response.setHeader("content-disposition", "inline; filename=\"My.pdf\"");
outStream = response.getOutputStream();
outStream.write(pdf);
outStream.flush();
outStream.close();

The report is executed and sent back to the browser, but I can not manage the file name, even if I installed it content-disposition. I am using Jboss 4.2.1. Do you know what I am missing?

EDIT : so is there a way to set the file name when the content is in a line?

+5
source share
6 answers

content-disposition: attachment ....

+8
source

MSIE URL- ( /) " ". filename Content-Disposition. .

URL PDF . /pdf http://example.com/context/pdf, /pdf/* http://example.com/context/pdf/report.pdf. , MSIE "report.pdf" "pdf" " ".

+3

java .

response.setHeader("Content-Disposition","inline; filename=\"MyFile.pdf\"");
response.setContentType("application/pdf; name=\"MyFile.pdf\"");
response.getOutputStream().write(pdfAsBytesArray);
+2

. /?

RFC, , , ...

+1

, - ( , - , ):

:

response.addHeader("content-length", String.valueOf(((FileInputStream) is).getChannel().size()));
response.addHeader("Content-disposition", "attachment; filename=\"MyFileName.doc\"");

. , , :

response.addHeader("Content-disposition", "attachment; filename=\"MyFileName.doc\"");
response.addHeader("content-length", String.valueOf(((FileInputStream) is).getChannel().size()));
0

. iframe, iframe html-, iframe pdf, html- iframe. html-, iframe.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
    <head>
        <title>${reportName}</title>
    </head>
    <body>
        <iframe src="/fcWeb/ReportPDFServlet" width="100%" height="100%"></iframe> 
    </body>
</html>
-2

All Articles