Hi,

I am reading Jason Hunter's book, now I am on page 161,
A "Hello World" image.

I copied the code directly from the book, and complied
it without problem, but when I tried to run the servlet
from a browser, the browser kept on spinning for ever.
I found the "frame.addNotify()" line causing the problem.

In my classpath, I have
java/jdk1.1.5/jdk1.1.5/lib/classes.zip:
java/JSDK2.0/lib/jsdk.jar:
plugins/java/jrun/servlets

Do you know what the problem is?

Thanks for your help.

Lily
=========================

package Lily;

import java.io.*;
import java.awt.*;
import javax.servlet.*;
import javax.servlet.http.*;

import Acme.JPM.Encoders.GifEncoder;

public class HG3 extends HttpServlet
{
        public void doGet(HttpServletRequest req, HttpServletResponse res)
                throws ServletException, IOException
        {
                //use binary output
                //ServletOutputStream out = res.getOutputStream();
                PrintWriter out = res.getWriter();

                        res.setContentType("text/plain");
                        out.println("TEST");
                        out.println("Another line");

                Frame frame = null;
                Graphics g = null;
                try
                {
                        //create an unshown frame
                        frame = new Frame();
                        //frame.addNotify();

                        //get a graphics region, using the Frame
                        Image image = frame.createImage(400,60);
                        g = image.getGraphics();

                        // draw Hello World
                        g.setFont(new Font("Serif", Font.ITALIC, 48));
                        g.drawString("Hello World!", 10, 50);

                        //encode the foo-screen image into a GIF
                        // and send it to the client
                        //res.setContentType("image/gif");
                        //GifEncoder encoder = new GifEncoder(image, out);
                        //encoder.encode();

                        out.close();

                }
                finally
                {
                        //clean up resources
                        if ( g != null )
                                g.dispose();
                        if ( frame != null )
                                frame.removeNotify();
                }


        }// end of doGet
}

___________________________________________________________________________
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