Java验证码工具类 :
public class PhoneCode {
private BufferedImage codeImg;
private String codeStr;
private static char code[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
public final String SESSION_CODE_NAME="code";
private PhoneCode(){
init();
}
public static PhoneCode codeInstance(){
return new PhoneCode();
}
public BufferedImage getCodeImg(){
return this.codeImg;
}
public String getCodeStr(){
return codeStr;
}
private Color getRandColor(int x,int y){
Random random = new Random();
if (x>255){
x=255;
}
if (y>255){
y=255;
}
int r = x+random.nextInt(y-x);
int g = x+random.nextInt(y-x);
int b = x+random.nextInt(y-x);
return new Color(r,g,b);
}
private