Canvas and Frame are both Component subclasses, so it shouldn't make much
difference which one you use. As I recall from when I last had to do it,
the Frame/notify/toolkit approach is correct.

The fundamental flaw with the code snippet you propose below is the lack of
a getImage() method in the Component object. <grin>. You've got to grab the
Toolkit first. I don't believe it will work without the addNotify() call,
either.

You are right about Linux or other Unix systems running without an X
Server: you won't have access to any of the AWT features, although there
are products that get around this.

At 12:09 AM 6/23/2000 +0200, K.V. Chandrinos wrote:
>William Crawford wrote:
>
>[..]
> > Essentially, you need to create an AWT context before using AWT calls. In a
> > servlet you need to do this explicitly, while in an Applet or Application
> > the context is pre-existing. That's why most of the sample code you see in
> > books won't run when dropped into a servlet.
> >
> > I haven't done this in a while, but if you create a new java.awt.Frame
> > object, call addNotify(), you should then be able to call
> > getToolkit().getImage("my.gif") on the Frame without any problems.
> >
>
>Actually, something a bit simpler could do the trick, like:
>
>Component dummyComponent = new Canvas();
>
>and then straight ahead into:
>
>             Image image = dummyComponent.getImage(filename);
>or
>             Image image = dummyComponent.createImage(
>                 new MemoryImageSource(width,height, pixels, 0,width) );
>
>But if you are on Linux, see another message by Chris, because importing
>java.awt.* won't mean that you DO have a native peer. Relying on the
>existance of native peers is quite a headache at times.
>
>Kostas
>
> > At 06:59 AM 6/22/2000 -0700, Jim Graham wrote:
> > >Hi,
> > >I've been trying to get an image into my servlet,
> > >but when I try it dies when it hits the call below:
> > >
> > >Image myImage =
> > >Toolkit.getDefaultToolkit().getImage("my.gif");
> > >
> > >
> > >Any ideas on how to get an image into a servlet?
> > >Thanks,
> > >Jim
> > >
> > >
> > >
> > >__________________________________________________
> > >Do You Yahoo!?
> > >Send instant messages with Yahoo! Messenger.
> > >http://im.yahoo.com/
> > >
> > >_______________________________________________________________________
> ____
> > >To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > >of the message "signoff SERVLET-INTEREST".
> > >
> > >Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > >Resources: http://java.sun.com/products/servlet/external-resources.html
> > >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
> > ---
> > William Crawford                                        + 01 617 577 7844
> > Invantage,
> Inc                                            [EMAIL PROTECTED]
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

---
William Crawford                                        + 01 617 577 7844
Invantage, Inc                                            [EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to