动态生成随机验证码

java 中验证码实现源码。

  (2009-06-23 10:38:31)
转载
标签: 

java

 

中验证码的实现

 

it

分类: IT/技术交流

java 中验证码的实现。。

 

第一步:

package com.jzh.ValidateCode;
import java.awt.Color;  
import java.awt.Font;  
import java.awt.Graphics2D;  
import java.awt.image.BufferedImage;  
import java.util.Random;  
import javax.imageio.ImageIO;  
import javax.servlet.ServletException;  
import javax.servlet.ServletOutputStream;  
import javax.servlet.http.HttpServlet;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
import javax.servlet.http.HttpSession;   

public class Validate extends HttpServlet {  
    
   
    private int width = 60;  
   
   
    private int height = 20;  
 
 
   
    private int codeCount = 4;  
 
   
    private int xx = 0;  
 
   
    private int fontHeight;  
 
   
    private int codeY;  
 
   
    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' };  
 
     
    public void init() throws ServletException {  
        // 从web.xml中获取初始信息  
        // 宽度  
        String strWidth = this.getInitParameter("width");  
        // 高度  
        String strHeight = this.getInitParameter("height");  
        // 字符个数  
        String strCodeCount = this.getInitParameter("codeCount");  
 
        // 将配置的信息转换成数值  
        try {  
            if (strWidth != null && strWidth.length() != 0) {  
                width = Integer.parseInt(strWidth);  
         

你可能感兴趣的:(java,验证码)