hi all,

I copy this draw image servlet from a book

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

import Acme.JPM.Encoders.GifEncoder;

public class HelloWorldGraphics extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {
    ServletOutputStream out = res.getOutputStream();  // binary output!

    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!" to the off screen graphics context
      g.setFont(new Font("Serif", Font.ITALIC, 48));
      g.drawString("Hello World!", 10, 50);

      // Encode the off screen image into a GIF and send it to the client
      res.setContentType("image/gif");
      GifEncoder encoder = new GifEncoder(image, out);
      encoder.encode();
    }
    finally {
      // Clean up resources
      if (g != null) g.dispose();
      if (frame != null) frame.removeNotify();
    }
  }
}

but I got this error message, pls tell me how to fix it.

java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value 
of the DISPLAY variable.
 at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
 at sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:58)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:120)
 at 
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:59)
 at sun.awt.motif.MToolkit.(MToolkit.java:56)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:120)
 at java.awt.Toolkit$2.run(Toolkit.java:495)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:488)
 at java.awt.Window.getToolkit(Window.java:416)
 at java.awt.Frame.addNotify(Frame.java:270)
 at HelloWorldGraphics.doGet(HelloWorldGraphics.java:20)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
 at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155)
 at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:168)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
 at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155)
 at com.sun.web.core.Context.handleRequest(Context.java:414)
 at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to