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 Murach's Java Servlets and JSP this week in the Servlets 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: 41060
    
  43
JSPs aren't meant for streaming binary content (and for all practical purposes, they can't). Use a servlet instead.


Ping & DNS - my free Android networking tools app
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: 41060
    
  43
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: 60752
    
  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: 60752
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to download binary file in jsp
 
Similar Threads
How to invoke file downloading from the JSP?
Test Installation
Download a binary file programmatically?
Getting unwanted characters at the start and end of a downloaded xml file
Downloading Excel file (containg BAR Chart) from JSP