Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP can't send a binary file

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does it mean we can only send binary data through Servlet?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic