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