首页 > 代码库 > jsp 验证码
jsp 验证码
<%@page import="java.awt.Graphics2D"%><%@page import="java.util.Random"%><%@page import="java.awt.Font"%><%@page import="javax.imageio.ImageIO"%><%@page import="java.awt.Color"%><%@page import="java.awt.Graphics"%><%@ page import="java.awt.image.BufferedImage"%><%@ page language="java" pageEncoding="utf-8" contentType="image/png" %><%int h = 45;int len = 4;int w = len*20;Random r = new Random();BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);Graphics2D g = (Graphics2D)img.getGraphics();//g.setColor(Color.RED);Color c = new Color(245,245,245);g.setColor(c);g.fillRect(0,0,w,h);String str = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXY3456789";g.setColor(Color.WHITE);for(int i=0;i<20;i++){ g.setFont(new Font("宋体",Font.BOLD,r.nextInt(20)+10)); c = new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255),r.nextInt(50)); String s = String.valueOf(str.charAt(r.nextInt(str.length()))); g.setColor(c); g.drawString(s, r.nextInt(w),r.nextInt(h));}StringBuffer ss = new StringBuffer();for(int i=0;i<len;i++){ int n = -5 +r.nextInt(10); g.rotate(n * Math.PI / 180); g.setFont(new Font("宋体",Font.BOLD,r.nextInt(15)+15)); c = new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255),r.nextInt(55)+200); String s = String.valueOf(str.charAt(r.nextInt(str.length()))); ss.append(s); g.setColor(c); g.drawString(s, 2+i*20,r.nextInt(10)+25);}session.setAttribute("checkcode",ss.toString());//添加干扰线 点for(int i=0;i<10;i++){ c = new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255),r.nextInt(80)); g.setColor(c); g.drawLine(r.nextInt(w), r.nextInt(h),r.nextInt(w), r.nextInt(h)); int size = r.nextInt(6)+5; g.fillOval(r.nextInt(w),r.nextInt(h),size,size);}c = new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255),r.nextInt(150));int hh = r.nextInt(h);for(int i=0;i<=300;i++){ g.setColor(c); double x = i; double y = hh+15*Math.sin(10*i*Math.PI/360); g.fillOval((int)x, (int)y, 5,5);}g.dispose();ImageIO.write(img, "png", response.getOutputStream());out.clear();out = pageContext.pushBody();%>
jsp 验证码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。