Java Code Examples for com.google.code.kaptcha.impl.DefaultKaptcha#createImage()
The following examples show how to use
com.google.code.kaptcha.impl.DefaultKaptcha#createImage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }
Example 2
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }
Example 3
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }
Example 4
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }
Example 5
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }
Example 6
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }
Example 7
Source File: CaptchaController.java From CAS with Apache License 2.0 | 5 votes |
/** * 谷歌kaptcha验证码路径 * * @param request * @param response * @throws Exception */ @GetMapping(value = "/kaptcha", produces = "image/png") public void kaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; DefaultKaptcha captchaProducer = KaptchaCodeUtils.getDefaultKaptcha(); OutputStream out = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { response.setHeader("Cache-Control", "no-store"); response.setContentType("image/png"); //生产验证码字符串并保存到session中 String createText = captchaProducer.createText(); request.getSession().setAttribute("captcha_code", createText); //使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中 BufferedImage challenge = captchaProducer.createImage(createText); ImageIO.write(challenge, "png", jpegOutputStream); //使用response输出流输出图片的byte数组 captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); out = response.getOutputStream(); out.write(captchaChallengeAsJpeg); out.flush(); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } finally { if (out != null) { out.close(); } } }