You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Wiedmann <mw...@miwie.in-berlin.de> on 2005/02/11 11:50:48 UTC

HttpServletResponse: binary data

I struggle with a problem I can't get resolved:

a bean method called by a commandLink/commandButton should write a file to the
client. This works in general except for the fact that I get "additional" data
in the file which is simply the complete HTML code of the page where the
link/button is included.

My code looks like (only the important parts shown):

HttpServletResponse r =
(HttpServletResponse)context.getExternalContext().getResponse();

r.setContentType("application/octet-stream");
r.setHeader("Content-Disposition",
            "attachment;filename=\"" + defFileName + "\");
ServletOutputStream s = r.getOutputStream();
..
iLen = in.read(b);
s.write(b, 0, iLen);
s.close();
// s.flush();
// r.flushBuffer();

So, how do I prevent this "additional" data?

Michael
-- 

Re: HttpServletResponse: binary data

Posted by Sean Schofield <se...@gmail.com>.
Sounds like a fine solution to me.  The reason why you were getting
that extraneous HTML is because JSF forms always post back to
themselves.  Since you have no navigation rules to navigate to a
different page, you are getting the same page back (after your action
method spits out your binary data.)

sean


On Fri, 11 Feb 2005 13:42:51 +0100, Michael Wiedmann
<mw...@miwie.in-berlin.de> wrote:
> Michael Wiedmann <mw...@miwie.in-berlin.de> wrote:
> ..
> > So, how do I prevent this "additional" data?
> 
> In the meantime I found "context.responseComplete();" which does what I want
> :-)
> 
> Michael
> --
>

Re: HttpServletResponse: binary data

Posted by Michael Wiedmann <mw...@miwie.in-berlin.de>.
Michael Wiedmann <mw...@miwie.in-berlin.de> wrote:
..
> So, how do I prevent this "additional" data?

In the meantime I found "context.responseComplete();" which does what I want
:-)

Michael
--