[opencms-dev] Can not override mimetype from jsp

Yves Glodt yg at mind.lu
Fri May 24 11:03:20 CEST 2013


Hello,

I have a JSP which reads a file from the local filesystem (not the vfs) and
outputs it to the browser.

But the content-type I set is not taken into account. Whatever I tried the
browser always gets text/html as content-type. Does OpenCms override it ?




Here is a code fragment:


ServletOutputStream outStream=response.getOutputStream();
 File myfile = new File("/mnt/data/"+filename);
FileInputStream input = new FileInputStream(myfile);

System.out.println(request.getRemoteAddr() + ": Size: " + myfile.length());

response.setContentType("application/pdf");
 response.setHeader("Content-Disposition","inline;filename=" + name);
response.setContentLength( (int) myfile.length() );


int readBytes = 0;
while((readBytes = buf.read()) != -1) {
outStream.write(readBytes);
 }
outStream.flush();
outStream.close();
 buf.close();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130524/07942530/attachment.htm>


More information about the opencms-dev mailing list