This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
JSPs aren't meant for streaming binary content (and for all practical purposes, they can't). Use a servlet instead.
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
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
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: 63208
    
  69

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: 63208
    
  69

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.
 
Have you checked out Aspose?
 
subject: how to download binary file in jsp
 
It's not a secret anymore!