<div dir="ltr">Ok, I got it working, without the cms.setContentType().<div><br></div><div style>The 2 steps necessary to make it work:</div><div style><br></div><div style>* Do not give the file any file extension</div><div style>
* Set the cache property to "bypass"</div><div style><br></div><div style>Without the latter it did not work whatever I did. Here an explanation: <a href="http://lists.opencms.org/pipermail/opencms-dev/2009q2/032259.html">http://lists.opencms.org/pipermail/opencms-dev/2009q2/032259.html</a></div>
<div style><br></div><div style>thanks to all and have a nice weekend</div><div style><br></div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 24 May 2013 12:19, Paul-Inge Flakstad <span dir="ltr"><<a href="mailto:flakstad@npolar.no" target="_blank">flakstad@npolar.no</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="NO-BOK" link="blue" vlink="purple"><div><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi again Yves,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Did you call it before calling response.setContentType() ? If I remember correctly, it’s important you do.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I remember I had the same issue (long time ago now), but I eventually got it working. As far as I can tell from my code, it was cms.setContentType() that did the trick.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Here’s a copy-paste from my JSP:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal" style="text-indent:35.4pt"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">byte[] rawContent = csvContent.getBytes(Charset.forName("UTF-8"));<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> cms.setContentType("text/csv;charset=UTF-8"); <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> response.setContentType("text/csv;charset=UTF-8");<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> response.setContentLength(rawContent.length);<u></u><u></u></span></p>
<p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> response.setHeader("Content-Disposition","attachment; filename=\"data.csv\""); <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> response.getOutputStream().write(rawContent, 0, rawContent.length);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> response.getOutputStream().flush();<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I’ve used this on a range of OpenCms versions (part of a module), and it works. Not tested on v8.5 though.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Cheers,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Paul<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a> [mailto:<a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a>] <b>On Behalf Of </b>Yves Glodt<br>
<b>Sent:</b> 24. mai 2013 12:02</span></p><div class="im"><br><b>To:</b> The OpenCms mailing list<br></div><b>Subject:</b> Re: [opencms-dev] Can not override mimetype from jsp<u></u><u></u><p></p></div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">Thanks for the replies so far !<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">@Paul: I added CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response); cms.setContentType((metadata != null) ? metadata.get(Metadata.CONTENT_TYPE) : "application/octet-stream");<u></u><u></u></p>
</div><div><p class="MsoNormal">but nothing changed, still text/html<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">@Siegfried: The download-jsp was called getFile.jsp. I renamed it to download (without any extension) but that did also not help :(<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">before: /getFile.jsp?file=/COMMON/bla/2013_02_DE.pdf&name=2013_02_DE.pdf<u></u><u></u></p>
</div><div><p class="MsoNormal">after: /download?file=/COMMON/bla/2013_02_DE.pdf&name=2013_02_DE.pdf<u></u><u></u></p></div></div><div><p class="MsoNormal"><u></u> <u></u></p></div></div><div><p class="MsoNormal" style="margin-bottom:12.0pt">
<u></u> <u></u></p><div><p class="MsoNormal">On 24 May 2013 11:19, Siegfried Ehret <<a href="mailto:s.ehret@eurelis.com" target="_blank">s.ehret@eurelis.com</a>> wrote:<u></u><u></u></p><div><div><p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hey,</span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">You may also check what is the default mime type for your file extension in WEB-INF/config/opencms-vfs.xml </span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">As an example, all files ending with “.html” will always have the “text/html” mime type:</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><mimetypes></span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">…</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><mimetype extension=".html" type="text/html" /></span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">…</span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"></mimetypes></span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Regards,</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Siegfried Ehret</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="FR" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">De :</span></b><span lang="FR" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a> [mailto:<a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a>] <b>De la part de</b> Paul-Inge Flakstad<br>
<b>Envoyé :</b> vendredi 24 mai 2013 11:10<br><b>À :</b> The OpenCms mailing list<br><b>Objet :</b> Re: [opencms-dev] Can not override mimetype from jsp</span><span lang="FR"><u></u><u></u></span></p></div></div><div><div>
<p class="MsoNormal"><span lang="FR"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi Yves,</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">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.</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">HTH :)</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Cheers,</span><span lang="FR"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Paul</span><span lang="FR"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><span lang="FR"><u></u><u></u></span></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a> [<a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">mailto:opencms-dev-bounces@opencms.org</a>] <b>On Behalf Of </b>Yves Glodt<br>
<b>Sent:</b> 24. mai 2013 11:03<br><b>To:</b> The OpenCms mailing list<br><b>Subject:</b> [opencms-dev] Can not override mimetype from jsp</span><span lang="FR"><u></u><u></u></span></p></div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p>
<div><p class="MsoNormal">Hello,<span lang="FR"><u></u><u></u></span></p><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal">I have a JSP which reads a file from the local filesystem (not the vfs) and outputs it to the browser.<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal">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 ?<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal">Here is a code fragment:<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p>
</div><div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> ServletOutputStream outStream=response.getOutputStream();<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> File myfile = new File("/mnt/data/"+filename);<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> FileInputStream input = new FileInputStream(myfile);<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> System.out.println(request.getRemoteAddr() + ": Size: " + myfile.length());<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> response.setContentType("application/pdf");<span lang="FR"><u></u><u></u></span></p></div><div>
<p class="MsoNormal"> response.setHeader("Content-Disposition","inline;filename=" + name);<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> response.setContentLength( (int) myfile.length() );<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> <span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> int readBytes = 0;<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> while((readBytes = buf.read()) != -1) {<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> outStream.write(readBytes);<span lang="FR"><u></u><u></u></span></p>
</div><div><p class="MsoNormal"> }<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> outStream.flush();<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal">
outStream.close();<span lang="FR"><u></u><u></u></span></p></div><div><p class="MsoNormal"> buf.close();<span lang="FR"><u></u><u></u></span></p></div></div></div></div></div></div></div><p class="MsoNormal" style="margin-bottom:12.0pt">
<br>_______________________________________________<br>This mail is sent to you from the opencms-dev mailing list<br>To change your list options, or to unsubscribe from the list, please visit<br><a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev" target="_blank">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br>
<br><br><br><u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div><br>_______________________________________________<br>
This mail is sent to you from the opencms-dev mailing list<br>
To change your list options, or to unsubscribe from the list, please visit<br>
<a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev" target="_blank">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br>
<br>
<br>
<br>
<br></blockquote></div><br></div>