JSP_JSP验证码简单生成方法,本文实例讲述了JSP验证码简单
response.getOutputStream());out.clear();out = pageContext.pushBody();% 。
250));g.fillRect(0,sRand);// 图象生效g.dispose();// 输出图象到页面ImageIO.write(image,width-1,18));//画边框//g.setColor(new Color());//g.drawRect(0,"no-cache");response.setDateHeader("Expires",所以只能直接生成 g.drawString(rand。
0);// 在内存中创建图象int width=60,g。
13*i+6,0,使图象中的认证码不易被其它程序探测到g.setColor(getRandColor(160,x+xl,16);}// 将认证码存入SESSIONsession.setAttribute("rand",b);}%%//设置页面不缓存response.setHeader("Pragma","No-cache");response.setHeader("Cache-Control",int bc){//给定范围获得随机颜色Random random = new Random();if(fc255) fc=255;if(bc255) bc=255;int r=fc+random.nextInt(bc-fc);int g=fc+random.nextInt(bc-fc);int b=fc+random.nextInt(bc-fc);return new Color(r。
y+yl);}// 取随机产生的认证码(4位数字)//String rand = request.getParameter("rand");//rand = rand.substring(0,rand.indexOf("."));String sRand="";for (int i=0;i4;i++){ String rand=String.valueOf(random.nextInt(10)); sRand+=rand; // 将认证码显示到图象中 g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110), width,可能是因为种子太接近,height-1);// 随机产生155条干扰线,Font.PLAIN。
0,javax.imageio.*" %%!Color getRandColor(int fc, height);//设定字体g.setFont(new Font("Times New Roman",200));for (int i=0;i155;i++){ int x = random.nextInt(width); int y = random.nextInt(height);int xl = random.nextInt(12);int yl = random.nextInt(12); g.drawLine(x, height, %@ page contentType="image/jpeg" import="java.awt.*, height=20;BufferedImage image = new BufferedImage(width。
20+random.nextInt(110)));//调用函数出来的颜色相同,y,java.awt.image.*, "JPEG",java.util.*。
BufferedImage.TYPE_INT_RGB);// 获取图形上下文Graphics g = image.getGraphics();//生成随机类Random random = new Random();// 设定背景色g.setColor(getRandColor(200,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/jsp/9595.shtml
