File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to download binary file in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to download binary file in jsp" Watch "how to download binary file in jsp" New topic
Author

how to download binary file in jsp

bappa
Greenhorn

Joined: Mar 11, 2008
Posts: 15
Hi i am trying to download binary file by a jsp file but it is showing the content (not all) on the browser. I want to save that file automatically to the client machine in a specified location. Please help.


S K B<br />SCJP 1.5 (83%)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
JSPs aren't meant for streaming binary content (and for all practical purposes, they can't). Use a servlet instead.


Ping & DNS - updated with new look and Ping home screen widget
bappa
Greenhorn

Joined: Mar 11, 2008
Posts: 15
then how to do it by servlet. please let me know... Give one sample code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
An example can be found under "Simple Stream" in the Code Barn.
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Originally posted by Ulf Dittmer:
An example can be found under "Simple Stream" in the Code Barn.


How do we render the images, if i try to invoke the servlet directly it gives:"The following image files are located under the WEB-INF directory and, thus, can not be seen with a browser unless streamed through the StreamServlet: "


Kishore
SCJP, blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

Exactly what that says. Any resources under WEB-INF are not directly accessible by URL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Originally posted by Bear Bibeault:
Exactly what that says. Any resources under WEB-INF are not directly accessible by URL.


Does that mean this example is just to show how to disallow stream of an image as compared to 'how to show a stream through a servlet?'
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

The example shows how to stream a resource through a servlet. This is useful for not only controlling access to resources hidden under WEB-INF from direct access, but for controlling the response headers so that the download acts in ways that you want.
 
jQuery in Action, 2nd edition
 
subject: how to download binary file in jsp
 
Similar Threads
Downloading Excel file (containg BAR Chart) from JSP
How to invoke file downloading from the JSP?
Getting unwanted characters at the start and end of a downloaded xml file
Download a binary file programmatically?
Test Installation