display image in servlet
<p>I am having the following requirement.
When the user cliock the buton the image should be displayed.The following code that i have tried gives me error</p>

<pre><code>    Toolkit tk = Toolkit.getDefaultToolkit();
    Image ima = Toolkit.getImage("C:\\DB.jpg");
    MediaTracker mt = new MediaTracker(new Canvas());
    mt.addImage(ima, 0);
    try 
    {
        mt.waitForAll();
    }
    catch(Exception x)  {}
    OutputStream os = res.getOutputStream();
    // Now create a writable image,
    BufferedImage bi = new BufferedImage(ima.getWidth(null), ima.getHeight(null), BufferedImage.TYPE_INT_RGB);
    bi.drawImage(ima, 0, 0, null); // Draw the loaded image onto a writable thing
    JPEGImageEncoder je = JPEGCodec.createJPEGEncoder(os);
    je.encode(ima);
    os.close();
}
</code></pre>
