BufferedImage im = new BufferedImage(60,20,BufferedImage.TYPE_INT_RGB); //第一个参数im表示一个图片对象 //JPG表示图片输出类型 //response.getOutputStream()代表一个响应的输出流,也就是说,你访问这个servlet.该servlet就会图片显示给你 ImageIO.write(im, "JPG",response.getOutputStream());
BufferedImage im = new BufferedImage(60,20,BufferedImage.TYPE_INT_RGB); //第一个参数im表示一个图片对象 //JPG表示图片输出类型 //response.getOutputStream()代表一个响应的输出流,也就是说,你访问这个servlet.该servlet就会图片显示给你 ImageIO.write(im, "JPG",response.getOutputStream());
Random rm = new Random(); Color c = new Color(rm.nextInt(255),rm.nextInt(255),rm.nextInt(255)); g.setColor(c); //填充整个图片的颜色 g.fillRect(0, 0, 60, 20);
g.setColor(new Color(rm.nextInt(255),rm.nextInt(255),rm.nextInt(255)));
g.setFont(new Font("华文隶书",Font.BOLD|Font.ITALIC,28));
g.drawString("8", 1, 18);
//随机产生4位数字
for(int i=0;i<4;i++){
g.setColor(new Color(rm.nextInt(255),rm.nextInt(255),rm.nextInt(255)));
g.setFont(new Font("Gungsuh",Font.BOLD|Font.ITALIC,22));
g.drawString(""+rm.nextInt(10), (i*15)+2, 18);
}
String str = "胸有激雷而面如平湖者可拜上将军";
for(int i=0;i<4;i++){
g.setColor(new Color(rm.nextInt(255),rm.nextInt(255),rm.nextInt(255)));
g.setFont(new Font("Gungsuh",Font.BOLD|Font.ITALIC,15));
g.drawString(""+str.charAt(rm.nextInt(str.length())), (i*15)+2, 18);
}
//将得到的四个数字保存到session中,以便当用户登录的时候,用来比较
request.getSession().setAttribute("piccode", sbf.toString());
boolean b_exist = login.validate(username,passwd);
//如果该用户存在
if(b_exist){
String pic = ""+request.getSession().getAttribute("piccode");
//比较验证码
if(!pic.equals("") && pic.equals(code)){
//向session中存入用户信息,以供其他中来使用
request.getSession().setAttribute("username", username);
response.sendRedirect("index.jsp");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有