java代码生成验证码(servlet)

java代码生成验证码(servlet)

ID:42615616

大小:51.46 KB

页数:9页

时间:2019-09-18

java代码生成验证码(servlet)_第1页
java代码生成验证码(servlet)_第2页
java代码生成验证码(servlet)_第3页
java代码生成验证码(servlet)_第4页
java代码生成验证码(servlet)_第5页
资源描述:

《java代码生成验证码(servlet)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、java验证码代码(转)产生图片servletimportjava.awt.Color;importjava.awt.Font;importjava.awt.Graphics2D;importjava.awt.image.BufferedImage;importjava.util.Random;importjavax.imageio.ImageIO;importjavax.servlet.ServletException;importjavax.servlet.ServletOutputStream;importjavax.servl

2、et.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;/***Packagename:com.skcc.sample.actionFilename:VerifyCodeServlet.java*Author:AdministratorDate:2008-9-4Description:VerifyCod

3、eServlet*/publicclassVerifyCodeServletextendsHttpServlet{/****/privatestaticfinallongserialVersionUID=1L;/***验证码图片的宽度。*/privateintwidth=60;/***验证码图片的高度。*/privateintheight=20;/***验证码字符个数第9页共9页*/privateintcodeCount=4;/***xx*/privateintxx=0;/***字体高度*/privateintfontHeight;/

4、***codeY*/privateintcodeY;/***codeSequence*/char[]codeSequence={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};/***初始化验证图片属性*/publicvoidinit()throwsServletException{//从web.

5、xml中获取初始信息//宽度StringstrWidth=this.getInitParameter("width");//高度StringstrHeight=this.getInitParameter("height");//字符个数StringstrCodeCount=this.getInitParameter("codeCount");//将配置的信息转换成数值try{if(strWidth!=null&&strWidth.length()!=0){width=Integer.parseInt(strWidth);第9页共9页}

6、if(strHeight!=null&&strHeight.length()!=0){height=Integer.parseInt(strHeight);}if(strCodeCount!=null&&strCodeCount.length()!=0){codeCount=Integer.parseInt(strCodeCount);}}catch(NumberFormatExceptione){e.printStackTrace();}xx=width/(codeCount+1);fontHeight=height-2;codeY

7、=height-4;}/***@paramreq*@paramresp*@throwsServletException*@throwsjava.io.IOException*/protectedvoidservice(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,java.io.IOException{//定义图像bufferBufferedImagebuffImg=newBufferedImage(width,height,BufferedI

8、mage.TYPE_INT_RGB);Graphics2Dgd=buffImg.createGraphics();//创建一个随机数生成器类Randomrandom=newRandom();//将图像填充为白色gd.se

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。