Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to download binary file using jsp at client side

Reply
Thread Tools

how to download binary file using jsp at client side

 
 
Girish T Deshpande
Guest
Posts: n/a
 
      07-01-2003
I am using Tomcat 4 and wish to download binary file(actualy an excel
and pdf file) to the local disk.
Since out.write ouputs the character array, I get error message when I
pass byte array.

The part of the code is below(I have set proper mime type)

FileReader f = new FileReader("C:/Tengli/jakarta-tomcat-4.1.24/webapps/ROOT/JavaExcel/ouput9.xls");

BufferedInputStream inputStream = new BufferedInputStream(new
FileInputStream("C:/Tengli/jakarta-tomcat-4.1.24/webapps/ROOT/JavaExcel/ouput9.xls"));

ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (true) {
int nBytes = inputStream.read(buffer);
if (nBytes < 0) break;
out.write(buffer, 0, nBytes);
}
//buffer = out.toByteArray();


I also get the error that out is already defined in
_jspService(......).
If I use other variable name instead of out it compiles and runs fine
but the file will be completely empty since it writes at unknown
place.


Could anyone give the entire code!

Thank you
 
Reply With Quote
 
 
 
 
Sergio Juan
Guest
Posts: n/a
 
      07-02-2003
Hi

"out" is a predefined object in the jsp (it is a Writer to
response.getOutputStream()) so use another name.
ITOH, the code looks fine.

Regards.

"Girish T Deshpande" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed) om...
> I am using Tomcat 4 and wish to download binary file(actualy an excel
> and pdf file) to the local disk.
> Since out.write ouputs the character array, I get error message when I
> pass byte array.
>
> The part of the code is below(I have set proper mime type)
>
> FileReader f = new

FileReader("C:/Tengli/jakarta-tomcat-4.1.24/webapps/ROOT/JavaExcel/ouput9.xl
s");
>
> BufferedInputStream inputStream = new BufferedInputStream(new
>

FileInputStream("C:/Tengli/jakarta-tomcat-4.1.24/webapps/ROOT/JavaExcel/oupu
t9.xls"));
>
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> byte[] buffer = new byte[1024];
> while (true) {
> int nBytes = inputStream.read(buffer);
> if (nBytes < 0) break;
> out.write(buffer, 0, nBytes);
> }
> //buffer = out.toByteArray();
>
>
> I also get the error that out is already defined in
> _jspService(......).
> If I use other variable name instead of out it compiles and runs fine
> but the file will be completely empty since it writes at unknown
> place.
>
>
> Could anyone give the entire code!
>
> Thank you



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute client-side code _after_ client-side validation? Bogdan ASP .Net 2 06-09-2008 01:31 PM
Client side script after client side validation with asp.net 2.0 Boss302 ASP .Net 0 11-21-2006 08:43 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Problem in adding template of server side control using client side scripts Lau Lei Cheong ASP .Net 1 10-13-2004 10:41 AM
Adding custom client-side onClick handler with client-side validator controls Zoe Hart ASP .Net Web Controls 1 01-08-2004 10:45 PM



Advertisments