基于J2EEStruts框架的课程设计实训项目——《BBS论坛系统》——实现用户身份验证表单中的图形验证码功能杨教授大学堂精心创作的优秀程序员职业提升必读系列资料基于J2EEStruts框架的课程设计实训项目——《BBS论坛系统》——、添加一个实现验证码功能的JavaBean组件类(1)类名称为VerifyCodeBean,.(2)编程该JavaBean杨教授大学堂,版权所有,盗版必究。1/.;.*;;.*;lassVerifyCodeBean{privateRandomrandom;privateintwidth;privateintheight;privateStringVerifyCode="";//存储随机产生的认证码(6位数字或者字母)publicVerifyCodeBean(){=90;=20;random=newRandom();//生成随机类}publicintgetHeight(){returnheight;}publicvoidsetHeight(intheight){=height;}publicRandomgetRandom(){returnrandom;杨教授大学堂,版权所有,盗版必究。2/10页杨教授大学堂精心创作的优秀程序员职业提升必读系列资料}publicvoidsetRandom(Randomrandom){=random;}publicStringgetVerifyCode(){returnVerifyCode;}publicvoidsetVerifyCode(StringverifyCode){VerifyCode=verifyCode;}publicintgetWidth(){returnwidth;}publicvoidsetWidth(intwidth){=width;}etRandomColor(intforegroundColor,intbackgroundColor){//给定范围获得随机颜色if(foregroundColor>255){foregroundColor=255;}if(backgroundColor>255){backgroundColor=255;}intr=foregroundColor+(backgroundColor-foregroundColor);intg=foregroundColor+(backgroundColor-foregroundColor);intb=foregroundColor+(backgroundColor-foregroundColor);杨教授大学堂,版权所有,盗版必究。3/10页杨教授大学堂精心创作的优秀程序员职业提升必读系列资料returnnewColor(r,g,b);}publicBufferedImagegetCreateVerifyImage(){//创建一个BufferedImage绘制你的动态图像BufferedImageimage=newBufferedImage(width,height,);/**创建完一个BufferedImage后,你需要得到图形环境进行绘制,一个Graphics或者Graphics2D对象*/Graphics2Dg2d=();Graphicsg=(Graphics)g2d;((180,250));/*生成有6个随机数字和杂乱背景的图片,数字和背景颜色会改变,服务器端刷新((-1)也会变)*/(0,0,width,height);(newFont("TimesNewRoman",,18));();(0,0,width-1,height-1);//((160,200));/*随机产生155条干扰线,使图象中的认证码不易被其它程序探测到*/for(inti=0;i<150;i++){int
基于j2ee+struts框架的课程设计实训项目——《bbs论坛系统》——实现用户身份验证表单中的图形验证码功能 来自淘豆网www.taodocs.com转载请标明出处.