救命啊,各位兄弟,关于验证码的怪问题!

yaping2002 2004-05-04 11:25:01
我的验证码jsp在windows下,运行后动态输出验证码图片,一切正常.
可是放到linux服务器上就不能运行,一遇到
Graphics g = image.getGraphics就报错,
我的服务器的jdk是1.4.2,tomcat是4.1.18.
大家帮帮忙吧,谢谢!
下面是源码:
<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);


int width=55, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
System.out.println("10");
Graphics g = image.getGraphics();
System.out.println("11");
g.setColor(Color.gray);
g.fillRect(0, 0, width, height);
g.setColor(Color.gray);
g.drawRect(0,0,width-1,height-1);
String rand = "";
Random ram = new Random();

String[] strRand = new String[]{"2","3","4","5","6","7","8","9","a","b","c","d"
,"e","f","g","h","i","j","k","m","n","q","p","r"
,"s","t","u","v","w","x","y","z","A","B","C","D","E"
,"F","G","H","I","J","K","M","N","R","P","Q","S"
,"T","U","V","W","X","Y","Z"};
for(int i=0;i<4;i++)
{
rand += strRand[ram.nextInt(strRand.length)];
}
session.setAttribute("rand",rand);
g.setColor(Color.black);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.drawString(rand,0,15);
Random random = new Random();

g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());

%>
...全文
130 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yyqllxh2004 2004-08-20
\tomcat\bin\canalina.sh文件
  • 打赏
  • 举报
回复
yyqllxh2004 2004-08-20
\tomcat\bin\canalina.sh文件

java -Djava.awt.headless=true
加参数就解决了,前两天刚弄出来的
  • 打赏
  • 举报
回复
mq612 2004-05-11
要在服务器启动脚本里面加入参数java -Djava.awt.headless=true
这样linux就不检测图形环境
  • 打赏
  • 举报
回复
mq612 2004-05-10
<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

response.reset();
int width=55, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//System.out.println("10");
Graphics g = image.getGraphics();
//System.out.println("11");
g.setColor(Color.gray);
g.fillRect(0, 0, width, height);
g.setColor(Color.gray);
g.drawRect(0,0,width-1,height-1);
String rand = "";
Random ram = new Random();

String[] strRand = new String[]{"2","3","4","5","6","7","8","9","a","b","c","d"
,"e","f","g","h","i","j","k","m","n","q","p","r"
,"s","t","u","v","w","x","y","z","A","B","C","D","E"
,"F","G","H","I","J","K","M","N","R","P","Q","S"
,"T","U","V","W","X","Y","Z"};
for(int i=0;i<4;i++)
{
rand += strRand[ram.nextInt(strRand.length)];
}
session.setAttribute("rand",rand);
g.setColor(Color.black);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.drawString(rand,0,15);
Random random = new Random();

g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());

%>
  • 打赏
  • 举报
回复
yaping2002 2004-05-04
我现在的测试方法是从我的client浏览器,访问我的linux服务器上的tomcat,
如果这样我的服务器也需要安装XWindow吗?
如果需要,那我如何知道我的服务器上安装了XWindow呢?

我在线等!

To: CoolAbu(阿卜-Never Stop)

谢谢您的帮助!
  • 打赏
  • 举报
回复
CoolAbu 2004-05-04
你的Linux服务器是不是没有安装xwindow?

如果没有安装XWindow好像不能用图形包的,你给你的Linux服务器装上XWindow试试。
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
加入

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-05-04 11:25
社区公告
暂无公告