aspose file tools*
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
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
Author

save jpeg image using sevlet and diplay it in html page

Meg Adal
Ranch Hand

Joined: Mar 12, 2002
Posts: 70
Hi,
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();
img.paint(g2);
try
{
OutputStream out = new FileOutputStream(filename);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(myImage);
out.close();
} catch (Exception e)
{
System.out.println(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?
Thanks
Megana
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
megana,
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.
regards
Prashanth
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: save jpeg image using sevlet and diplay it in html page