我尝试使用 JCaptcha 组件制作验证码,我需要在相关的 servlet 中对图像进行编码。所以根据JCaptcha Tutorial,我应该使用JPEGImageEncoder,它与JDK7不兼容。我还可以做些什么?
这是代码的相关部分:
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
BufferedImage challenge =
CaptchaServiceSingleton.getInstance().getImageChallengeForID(captchaId,
httpServletRequest.getLocale());
JPEGImageEncoder jpegEncoder =
JPEGCodec.createJPEGEncoder(jpegOutputStream);
jpegEncoder.encode(challenge);
} catch (IllegalArgumentException e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} catch (CaptchaServiceException e) {
httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}