[opencms-dev] response.setContentType()

SCHEDENIG Marian Marian.Schedenig at qualysoft.com
Thu Nov 16 15:30:50 CET 2006


Hi!

I'm trying to manually stream binary data to the client from within a
JSP. The idea is to send images from the VFS so I can set the attachment
mode to "inline", in which case most browsers show a dialog asking the
user where to save the image data.

My problem is that response.setContentType() seems to have no effect.
When reading the content type from the response right after the set
command, I still get "text/html".

Is there any way to do this without writing a full servlet?

My test code (without the attachment type) looks like this:


<%@ page session="false" import="java.io.*, org.opencms.jsp.*,
org.opencms.file.*, javax.servlet.*" %>
<%
    response.setContentType("image/gif");
    CmsObject cmsobj = new CmsJspActionElement(pageContext, request,
response).getCmsObject();
    CmsFile fout =
cmsobj.readFile("/Josefstadt_Gallery/Bilder_Allgemein/Sitzplan_Josefstad
t.gif");
    byte[] bytes=fout.getContents();
    response.setContentLength(bytes.length);
    ServletOutputStream sout = response.getOutputStream();
    sout.write(bytes);
    sout.flush();
    response.flushBuffer();
%>


Thx,
Marian.



More information about the opencms-dev mailing list