• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

save jpeg image using sevlet and diplay it in html page

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic