Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to download an image

 
pravallika reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to download images of any type from the server.my server is unix based.i need help help in coding.what should i give as content type in the response of jsp.
i am using jsp.
i had given image/jpg or image.gif as content type.but it is giving error as no preview parameters.
help me..
thanks
pravii
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is optimized for text - images are binary. The best way to serve binary data is through a servlet where you have total control over the response and can set the content type and length.
Servlets are just as simple as JSP, after all, a JSP is turned into a servlet. There is no reason not to use a mix of JSP and servlets for your application.
Bill
 
David Yutzy
tumbleweed and gunslinger
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got an issue with this approach...
I have a JSP file that has the following (<> removed so you can see the syntax):
IMG SRC="/servlet/imageservlet?id=6"
The problem is when I refresh the page, sometimes the image appears, sometimes it doesn't...
The same code, pointing to a PHP file for image retrieval works just fine...
Any suggestion?
P.S.
The "id=" is pulling the image from a mySQL DB given the "id" of the image table.
 
Dave Van Even
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just MAP the servlet to a file with the right extension..
also make shure you write the right response content type !!

res.setContentType("image/gif");
and map the servlet to somthing like: /imageservlet.gif

that should work
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic