Esempio n. 1
0
  private void genernateCaptchaImage(
      final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    ServletOutputStream out = response.getOutputStream();
    try {
      String captchaId = request.getSession(true).getId();
      BufferedImage challenge =
          (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale());
      ImageIO.write(challenge, "jpg", out);
      out.flush();
    } catch (CaptchaServiceException e) {
      logger.error(e.getMessage(), e);
    } finally {
      out.close();
    }
  }
Esempio n. 2
0
  protected void genernateCaptchaImage(
      final HttpServletRequest request, final HttpServletResponse response) {

    ServletUtils.setDisableCacheHeader(response);
    response.setContentType("image/png");
    ServletOutputStream out = null;
    try {
      out = response.getOutputStream();
      String captchaId = request.getSession(true).getId();
      BufferedImage challenge =
          (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale());
      // String writerNames[] = ImageIO.getWriterFormatNames();
      ImageIO.write(challenge, "png", out);
      out.flush();
    } catch (IOException | CaptchaServiceException e) {
      log.error("生成验证码出错", e);
    } finally {
      try {
        out.close();
      } catch (IOException e) {
        log.error("生成验证码出错", e);
      }
    }
  }