当前位置: 代码迷 >> Web前端 >> 每日学习点 验证码之Jcaptcha
  详细解决方案

每日学习点 验证码之Jcaptcha

热度:193   发布时间:2012-10-06 17:34:01.0
每天学习点 验证码之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();

  相关解决方案