jsp 驗證碼

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   sp   for   java   

<%@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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.