//写汉字 String base = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740"; //写4个字 Color c = Color.BLUE; g.setColor(c); Font font = new Font("宋体",Font.ITALIC, 20); g.setFont(font); StringBuffer sb = newStringBuffer(); //产生汉字 for(int i=0;i<4;i++){ int location = newRandom().nextInt(base.length()-1); char chr = base.charAt(location); sb.append(chr+""); } checkCode=sb.toString(); Graphics2D gd = (Graphics2D) g; gd.rotate(0.05); //把汉字写到图片上 g.drawString(checkCode, 10, 20); } public static voidoutImage(OutputStream os) throws IOException{ //创建图片 BufferedImage image = new BufferedImage(WIDTH, HEIGHT, IMAGETYPE); //得到图型 Graphics g = image.getGraphics(); // 设置图片背景色 setBackground(g); //向图片上写边框 setBorder(g); //向图片上写干扰线 setRandomLine(g); // 7、向图片上写数据 setFont(g); // 8、把图片写给浏览器 ImageIO.write(image, "gif", os); } //清楚浏览器缓存 response.setIntHeader("expires", 0); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); //通知浏览器以图片的方式打开 response.setHeader("Content-Type", "image/jpeg");
用Session来完成用户登录,防止表单重复提交。
最新推荐文章于 2021-02-26 23:36:18 发布