File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP can't send a binary file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP can Watch "JSP can New topic
Author

JSP can't send a binary file

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Since JSP Engine creates a JSPWriter (out) object from resonse, if we call response.getOutpuStream(), we will always get IllegalStateException @ runtime.

This concludes that we can't send a binary file (data) to client using JSP.
saqib sarwar
Ranch Hand

Joined: Mar 30, 2007
Posts: 77
yes actually you cannot call response.getOutputStream() after calling response.getWriter() in any servlet.

and jsp translates and compiles down to a servlet, and implicit out object is being got from getWriter() method, so we can not send Binary Stream in JSP page.

Kind Regards


SCJP5 95%, SCWCD 85%<br />Knowledge is the Life of Mind
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

So does it mean we can only send binary data through Servlet?


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Yes.


Ping & DNS - my free Android networking tools app
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
hendy,
The answer to your question is we can send text as well as binary data using servlet but not both at a time.

My original question was :

Can we send binary data through JSP anyhow ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
We can send text as well as binary data using servlet but not both at a time.

I don't quite like the way this is phrased - text bytes are a subset of all (binary) bytes characters.

Can we send binary data through JSP anyhow ?

Practically, no. Have a look at the Java source code that gets created from a JSP page, and you'll notice the difficulties.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP can't send a binary file