[opencms-dev] Can not override mimetype from jsp

Yves Glodt yg at mind.lu
Fri May 24 12:02:16 CEST 2013


Thanks for the replies so far !

@Paul: I added  CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
cms.setContentType((metadata != null) ? metadata.get(Metadata.CONTENT_TYPE)
: "application/octet-stream");
but nothing changed, still text/html

@Siegfried: The download-jsp was called getFile.jsp. I renamed it to
download (without any extension) but that did also not help :(


before: /getFile.jsp?file=/COMMON/bla/2013_02_DE.pdf&name=2013_02_DE.pdf
after: /download?file=/COMMON/bla/2013_02_DE.pdf&name=2013_02_DE.pdf



On 24 May 2013 11:19, Siegfried Ehret <s.ehret at eurelis.com> wrote:

>  Hey,****
>
> ** **
>
> You may also check what is the default mime type for your file extension
> in WEB-INF/config/opencms-vfs.xml ****
>
> As an example, all files ending with “.html” will always have the
> “text/html” mime type:****
>
> <mimetypes>****
>
> …****
>
> <mimetype extension=".html" type="text/html" />****
>
> …****
>
> </mimetypes>****
>
> ** **
>
> Regards,****
>
> ** **
>
> Siegfried Ehret****
>
> ** **
>
> *De :* opencms-dev-bounces at opencms.org [mailto:
> opencms-dev-bounces at opencms.org] *De la part de* Paul-Inge Flakstad
> *Envoyé :* vendredi 24 mai 2013 11:10
> *À :* The OpenCms mailing list
> *Objet :* Re: [opencms-dev] Can not override mimetype from jsp****
>
> ** **
>
> Hi Yves,****
>
> ** **
>
> Try calling CmsJspActionElement.setContentType(java.lang.String) as well.
> I see I’ve used that method in my similar JSPs, and they work like they
> should.****
>
> ** **
>
> HTH :)****
>
> ** **
>
> Cheers,****
>
> Paul****
>
> ** **
>
> *From:* opencms-dev-bounces at opencms.org [
> mailto:opencms-dev-bounces at opencms.org <opencms-dev-bounces at opencms.org>]
> *On Behalf Of *Yves Glodt
> *Sent:* 24. mai 2013 11:03
> *To:* The OpenCms mailing list
> *Subject:* [opencms-dev] Can not override mimetype from jsp****
>
> ** **
>
> 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();****
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130524/b9c7bcb4/attachment.htm>


More information about the opencms-dev mailing list