tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Souther <bsout...@fwdco.com>
Subject Re: How to Display a byte array (contents of a MS DOC fie, Excel, ..) in web browser
Date Fri, 29 Oct 2004 01:41:44 GMT
Set the content type.
Set the content disposition.
Get a servletOutputStream from the response object.
Write the bytes to the outputStream.
Flush the stream.

Sort of like this...
You'll need to add exception handling and probably buffering if you're 
streaming the byte array in and out at the same time.
There are lots of examples on the web for doing that.
This should get you started.


response.setContentType("application/vnd.ms-word");

response.setHeader(
    "Content-Disposition", "attachment; filename=myFile.doc");

ServletOutputStream out = response.getOutputStream();

for(int i = 0; i < byteArray.length; i++){
    out.write(byteArray[i]);
}
out.flush();







On Thu, 2004-10-28 at 21:11, Daxin Zuo wrote:
> I receive a byte array from a remote server, and the servlet will display it
> on the browser. The byte array contains a MS DOC file. If I simply convert
> it to a String, the contents will be meaningless.
> Please forward instruction.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message