1、验证码生成页面ValiCode.jsp:
String s="";
int count=0;
Random rand=new Random();
count=rand.nextInt(9999);
while(count<1000){
count=rand.nextInt(9999);
}
s+=count;
session.setAttribute("validate",s);
response.setContentType("image/gif");
BufferedImage image=new BufferedImage(65,30,BufferedImage.TYPE_INT_RGB);
Graphics gra=image.getGraphics();
gra.setColor(Color.RED);
gra.fillRect(1,1,63,28);
gra.setColor(Color.ORANGE);
gra.setFont(new Font("隶书",Font.PLAIN,28));
char c;
for(int i=0;i<4;i++){
c=s.charAt(i);
gra.drawString(c+" ",i*15+4,23);
}
OutputStream toClient=response.getOutputStream();
JPEGImageEncoder jpg=JPEGCodec.