aspose file tools*
The moose likes Servlets and the fly likes how to download an image 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 » Servlets
Bookmark "how to download an image " Watch "how to download an image " New topic
Author

how to download an image

pravallika reddy
Greenhorn

Joined: Feb 24, 2002
Posts: 10
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

Joined: Mar 22, 2000
Posts: 12676
    
    5
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


Java Resources at www.wbrogden.com
David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
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

Joined: Jul 19, 2001
Posts: 101
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to download an image
 
Similar Threads
IllegalStateException:........
Problem running Servlet
Directive : include file
Downloading image file using JSP
calling an action through html:img tag