linux下验证码功能不能正常显示

步骤方法:
1、修改${TOMCAT_HOME}/bin/catalina.sh (windows修改catalina.bat)。
2、查找到-Djava.io.tmpdir="$CATALINA_TMPDIR"这行,
3、并在这一行下加入:-Djava.awt.headless=true \,
4、修改好“保存”再重启tomcat后网页的验证码就可以正确显示了。
阅读更多
换一批

->>> JSP验证码的问题(验证码不能正常显示

10-26

各位高手可能对下面的这段很熟悉,这就是在网上很很流行的彩色验证码,不过我下载下来后不知道什么原因,一直都无法正常显示,显示的是一个框和一个红色的叉。rn不知道是哪里有问题,请高手不吝赐教!rnrn<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>rn<%!rnColor getRandColor(int fc,int bc)//给定范围获得随机颜色rn Random random = new Random();rn if(fc>255) fc=255;rn if(bc>255) bc=255;rn int r=fc+random.nextInt(bc-fc);rn int g=fc+random.nextInt(bc-fc);rn int b=fc+random.nextInt(bc-fc);rn return new Color(r,g,b);rn rn%>rn<%rn//设置页面不缓存rnresponse.setHeader("Pragma","No-cache");rnresponse.setHeader("Cache-Control","no-cache");rnresponse.setDateHeader("Expires", 0);rnrn// 在内存中创建图象rnint width=60, height=20;rnBufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);rnrn// 获取图形上下文rnGraphics g = image.getGraphics();rnrn//生成随机类rnRandom random = new Random();rnrn// 设定背景色rng.setColor(getRandColor(200,250));rng.fillRect(0, 0, width, height);rnrn//设定字体rng.setFont(new Font("Times New Roman",Font.PLAIN,18));rnrn//画边框rn//g.setColor(new Color());rn//g.drawRect(0,0,width-1,height-1);rnrnrn// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到rng.setColor(getRandColor(160,200));rnfor (int i=0;i<155;i++)rnrn int x = random.nextInt(width);rn int y = random.nextInt(height);rn int xl = random.nextInt(12);rn int yl = random.nextInt(12);rn g.drawLine(x,y,x+xl,y+yl);rnrnrn// 取随机产生的认证码(4位数字)rnString sRand="";rnfor (int i=0;i<4;i++)rn String rand=String.valueOf(random.nextInt(10));rn sRand+=rand;rn // 将认证码显示到图象中rn g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成rn g.drawString(rand,13*i+6,16);rnrnrn// 将认证码存入SESSIONrnsession.setAttribute("rand",sRand);rnrnrn// 图象生效rng.dispose();rnrn// 输出图象到页面rnImageIO.write(image, "JPEG", response.getOutputStream());rnrnrn%>rnrn咋回事呢rn

JSP验证码的问题(验证码不能正常显示

08-02

各位高手可能对下面的这段很熟悉,这就是在网上很很流行的彩色验证码,不过我下载下来后不知道什么原因,一直都无法正常显示,显示的是一个框和一个红色的叉。rn不知道是哪里有问题,请高手不吝赐教!rnrn<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>rn<%!rnColor getRandColor(int fc,int bc)//给定范围获得随机颜色rn Random random = new Random();rn if(fc>255) fc=255;rn if(bc>255) bc=255;rn int r=fc+random.nextInt(bc-fc);rn int g=fc+random.nextInt(bc-fc);rn int b=fc+random.nextInt(bc-fc);rn return new Color(r,g,b);rn rn%>rn<%rn//设置页面不缓存rnresponse.setHeader("Pragma","No-cache");rnresponse.setHeader("Cache-Control","no-cache");rnresponse.setDateHeader("Expires", 0);rnrn// 在内存中创建图象rnint width=60, height=20;rnBufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);rnrn// 获取图形上下文rnGraphics g = image.getGraphics();rnrn//生成随机类rnRandom random = new Random();rnrn// 设定背景色rng.setColor(getRandColor(200,250));rng.fillRect(0, 0, width, height);rnrn//设定字体rng.setFont(new Font("Times New Roman",Font.PLAIN,18));rnrn//画边框rn//g.setColor(new Color());rn//g.drawRect(0,0,width-1,height-1);rnrnrn// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到rng.setColor(getRandColor(160,200));rnfor (int i=0;i<155;i++)rnrn int x = random.nextInt(width);rn int y = random.nextInt(height);rn int xl = random.nextInt(12);rn int yl = random.nextInt(12);rn g.drawLine(x,y,x+xl,y+yl);rnrnrn// 取随机产生的认证码(4位数字)rnString sRand="";rnfor (int i=0;i<4;i++)rn String rand=String.valueOf(random.nextInt(10));rn sRand+=rand;rn // 将认证码显示到图象中rn g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成rn g.drawString(rand,13*i+6,16);rnrnrn// 将认证码存入SESSIONrnsession.setAttribute("rand",sRand);rnrnrn// 图象生效rng.dispose();rnrn// 输出图象到页面rnImageIO.write(image, "JPEG", response.getOutputStream());rnrnrn%>

没有更多推荐了,返回首页