关于LINUXG下servlet验证码的问题
我们的项目用的是struts1.2,我用sertlet写了一个生成验证吗的程序,
BufferedImage buffImg = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
Font font = new Font("Times New Roman", Font.PLAIN, 18);
g.setFont(font);
g.setColor(Color.BLACK);
g.drawRect(0, 0, width - 1, height - 1);
g.setColor(Color.GRAY);
Random random = new Random();
for (int i = 0; i < 40; i++) {
int x1 = random.nextInt(width);
int y1 = random.nextInt(height);
int x2 = random.nextInt(10);
int y2 = random.nextInt(10);
g.drawLine(x1, y1, x1 + x2, y1 + y2);
}
StringBuffer randomCode = new StringBuffer();
for (int i = 0; i < 4; i++) {
String strRand = String.valueOf(random.nextInt(10));
g.setColor(Color.RED);
g.drawString(strRand, 13 * i + 6, 16);
randomCode.append(strRand);
}
//将验证码放入cookie中
CookieHelper.setCookie(response,"random",randomCode.toString());
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(buffImg);
out.close();
代码在linux下运行了一到两天,验证码就无法显示了,报的错误如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
root cause
java.lang.NoClassDefFoundError
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1141)
com.suntoward.scihoo.web.servlet.ValidateCode.doGet(ValidateCode.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.9
换了几种方式还是不行,不知道为什么出现这种问题。请各位大侠帮忙看看呀