高手何在????????:Servlet高手急救:欲从servlet输出图形,请问linux环境下如何配置,web服务器为tomcat

Computer_lover 2001-09-27 11:39:57
注意:服务器为linux
代码为:
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.awt.*;
import java.awt.image.*;

public class JPEGServlet extends HttpServlet {

private Font mFont=new Font("隶书", Font.BOLD,32);

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{

response.setContentType("image/jpeg");

ServletOutputStream out=response.getOutputStream();


BufferedImage image=new BufferedImage(160,64,BufferedImage.TYPE_INT_RGB);

Graphics g=image.getGraphics();

g.setColor(Color.black);
g.fillRect(0,0,160,64);
g.setColor(Color.green);
g.setFont(mFont);


g.drawString("中国",10,60);


JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);

out.close();
}

public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doGet(request,response);
}

}
执行时报以下错误:
Internal Servlet Error:

java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java, Compiled Code)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java, Compiled Code)
at java.awt.Font.initializeFont(Font.java, Compiled Code)
at java.awt.Font.(Font.java, Compiled Code)
at JPEGServlet.(JPEGServlet.java, Compiled Code)
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java, Compiled Code)
at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java, Compiled Code)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java, Compiled Code)
at org.apache.tomcat.core.Handler.service(Handler.java, Compiled Code)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java, Compiled Code)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java, Compiled Code)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java, Compiled Code)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java, Compiled Code)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java, Compiled Code)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java, Compiled Code)
at java.lang.Thread.run(Thread.java, Compiled Code)
...全文
49 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sharetop 2001-09-27

我也试了一下,没问题的。

两帖一共80分,都是我的吧:)

我的mail: ycshowtop@21cn.com
回复
Computer_lover 2001-09-27
成功了,应该先起xwindow,再起tomcat即可
谢谢你,交个朋友吧
wxbmailbox@eyou.com
回复
sharetop 2001-09-27

不好意思,今天我一直上不了CSDN,总是报数据库连接超时!:(

你说的这个错误说明java没能找到本地图形环境。

你是否安装了图形环境,是否在图形环境下运行tomcat?

我也试一下吧。下去换个环境看一下,不知等会能不能再进来。

回复
Computer_lover 2001-09-27
主啊,救救我吧!!!!!!!!!!!
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-09-27 11:39
社区公告
暂无公告