Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Download image(jpg format) using URL in jsp  RSS feed

 
velgapudi suresh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



Regards,
Suresh.V

 
Tim Moores
Saloon Keeper
Posts: 3881
91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 index=readImg.read(rb, 0, len);
//st1.close();
response.reset();
response.setContentType("image/JPG");
response.setHeader("Content-disposition","attachment; filename=" +filename);
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();


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.



Suresh.V
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!