This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes save jpeg image using sevlet and diplay it in html page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "save jpeg image using sevlet and diplay it in html page" Watch "save jpeg image using sevlet and diplay it in html page" New topic

save jpeg image using sevlet and diplay it in html page

Meg Adal
Ranch Hand

Joined: Mar 12, 2002
Posts: 70
I have one servlet which creates jpeg image.
I want to save the image in same folder where my servlet is and then diplay that image in the html page.
I wrote following code to create image
// here img is instance of class Myimg which extends canvas
// following code is in Myservlet class
BufferedImage myImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = myImage.createGraphics();
OutputStream out = new FileOutputStream(filename);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
} catch (Exception e)
If i wrote same code in class that extends frame(with some modification) the code works fine and saves the image in file with name specified
but the code is not working in servlet
Can anybody help me in this matter?
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Javaranch has a naming policy which is strictly enforced. Please change your display name to conform with this policy if you wish to keep posting here. Thanks.

Matthew Phillips
Prashanth menon
Ranch Hand

Joined: Feb 20, 2001
Posts: 65
Hi megana
The problem if there is no exception is not with the code. The file has been saved. The file is saved to a default directory that depends on the container you use. If you use Tomcat4.0 on Winnt this file is saved in the System32 folder.
For Jrun3.0 the file is written to Jrunroot/servers/default folder
Actually you can write a servlet that reads from the file and the returns image.
I had posted on this earlier.
Don't get me started about those stupid light bulbs.
subject: save jpeg image using sevlet and diplay it in html page
Similar Threads
Extending BufferedImage
Casting problem. Image to BufferedImage
Swing to Image conversion
Bmp, gif, jpeg
Displaying images and thumbnails directly from database