验证码下载,验证码实现

时间:2013-01-26 14:53:23
【文件属性】:
文件名称:验证码下载,验证码实现
文件大小:9KB
文件格式:RAR
更新时间:2013-01-26 14:53:23
验证码 简单的验证码实现 public static void generateTokenImage(HttpServletResponse response, HttpSession session, int width, int height) throws IOException { //设置响应内容为图片格式 response.setContentType("image/jpeg"); //禁止浏览器缓存 response.addHeader("pragma", "NO-cache"); response.addHeader("Cache-Control", "no-cache"); response.addDateHeader("Expries", 0); //绘制图片 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); //以下填充背景颜色 g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); //设置字体颜色 g.setColor(Color.RED); Font font = new Font("Arial", Font.BOLD, 18); g.setFont(font); //绘制 String token = (String) session.getAttribute(TOKEN_KEY_NAME); g.drawString(token, 5, height - 2); g.dispose(); //发送内容到客户端 ServletOutputStream out = response.getOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(image); out.close(); }
【文件预览】:
token
----.project(1KB)
----.mymetadata(288B)
----WebRoot()
--------fail.jsp(37B)
--------success.jsp(7B)
--------WEB-INF()
--------index.jsp(816B)
--------META-INF()
--------next.jsp(380B)
----.myeclipse()
----src()
--------guides()
----.classpath(340B)

网友评论