`
sbl2255
  • 浏览: 218288 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

每天学习点 验证码之Jcaptcha

阅读更多
如图:



代码:
ByteArrayOutputStream jpgout = new ByteArrayOutputStream();
		String id = req.getSession().getId();
		BufferedImage bimg = new DefaultManageableImageCaptchaService().getImageChallengeForID(id,req.getLocale());
		JPEGImageEncoder imgcode = JPEGCodec.createJPEGEncoder(jpgout);
		imgcode.encode(bimg);
		byte[] captchaChallengeAsJpeg = jpgout.toByteArray();
		resp.setHeader("Cache-Control", "no-store");
		resp.setHeader("Pragma", "no-cache");
		resp.setDateHeader("Expires", 0);
		resp.setContentType("image/jpeg");
		ServletOutputStream responseOutputStream = resp.getOutputStream();
		responseOutputStream.write(captchaChallengeAsJpeg);
		responseOutputStream.flush();
		responseOutputStream.close();

  • 大小: 4.7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics