This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply 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: 35237
    
    7
JSPs aren't meant for streaming binary content (and for all practical purposes, they can't). Use a servlet instead.


Android appsImageJ pluginsJava web charts
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: 35237
    
    7
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: 56180
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56180
    
  13

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to download binary file in jsp
 
Similar Threads
Download a binary file programmatically?
Downloading Excel file (containg BAR Chart) from JSP
Getting unwanted characters at the start and end of a downloaded xml file
Test Installation
How to invoke file downloading from the JSP?