File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Download image(jpg format) using URL 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 "Download image(jpg format) using URL in jsp" Watch "Download image(jpg format) using URL in jsp" New topic

Download image(jpg format) using URL in jsp

velgapudi suresh
Ranch Hand

Joined: Aug 11, 2006
Posts: 32
Hi Every one,

In my application image download functionality is there. One beside of image we have a button to download the image using url functionality.

How we can do it, i tried it but image storing it 0 size.

anyone help out in this problem.


Tim Moores

Joined: Sep 21, 2011
Posts: 2408
We're going to need a lot more information about what, exactly, you tried, and how, exactly, that didn't work.
velgapudi suresh
Ranch Hand

Joined: Aug 11, 2006
Posts: 32
Hi Moores,

Thank you for the reply.

I tried below code

String imgLen = "D://sahi.JPG";

String filename = "image005.jpg";

int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = new BufferedInputStream(
new FileInputStream(imgLen));
int, 0, len);
response.setHeader("Content-disposition","attachment; filename=" +filename);

this was done in my jsp scrip-let code. When i run the page i am able to get save window with the filename. But the content not able to read .

Where i was done mistake and where i can change my code.

please help out me.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60041

You should be doing this in a servlet. JSPs are meant as templates for text content, not images or other binary formats. Please read this article to understand what JSP is and why your approach is folly.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Download image(jpg format) using URL in jsp
Similar Threads
how we can create xls file in java
How to enable downloads
Regarding Upload a file
General Question Regarding Image Processing
Upload/Download of Files In Java