JCaptcha4Struts2使用.docVIP

  • 3
  • 0
  • 约4.25万字
  • 约 10页
  • 2017-08-04 发布于河南
  • 举报
这是官网网址(ps:看到很多英文,不要害怕,都是很基本的,认真看完后,思路会很清晰) /p/jcaptcha4struts2/wiki/QuickStart 这是一个网上的文章(ps:有一定的参考价值,实际上我在上面的文章收获的不是很大) /blog/1038919 先加入jar包可以到这里下载HYPERLINK /p/jcaptcha4struts2/downloads/list/p/jcaptcha4struts2/downloads/list maven项目的话加入依赖 dependencies dependency groupIdcom.google.code.jcaptcha4struts2/groupId artifactIdjcaptcha4struts2/artifactId version2.0.1/version /dependency /dependencies 首先要显示验证码 我们进入jar包里面 可以看到有一个JCaptchaImageAction.class的文件 进入一看具体代码如下 public class JCaptchaImageAction extends ActionSupport { private static final String IMAGE_FORMAT = jpg; private static final long serialVersionUID = 563498642053643243L; private static final Log LOG = LogFactory.getLog(JCaptchaImageAction.class); /** * Holds the byte[] for JPEG encoded Captcha Image. */ private byte[] captchaImage; /** * Action execution logic, which generates the Captcha Image Stream and sets the JPEG encoded * byte stream to captchaImage field. * p * Subsequent to invocation of this method, the generated captcha is available through * {@link #getCaptchaImage()} method. * * @return action forward string * * @throws Exception */ public String execute() { ByteArrayOutputStream imageOut = new ByteArrayOutputStream(); HttpServletRequest request = ServletActionContext.getRequest(); // Captcha Id is the session ID String captchaId = request.getSession().getId(); if (LOG.isDebugEnabled()) { LOG.debug(Generating Captcha Image for SessionID : + captchaId); } // Generate Captcha Image BufferedImage image = getImageCaptchaService().getImageChallengeForID(captchaId, request.getLocale()); // Encode to JPEG Stream try { ImageIO.write(image, IMAGE_FORMAT, imageOut); } catch (IOException e) { LOG.error(Unable to JPEG encode the Captcha Image due to IOException, e); throw new IllegalArgumentException(Unable to JPEG encode the Captcha Image, e); } // Get byte[] for image captchaImage = imageOut.toByteArray(); return SUCCESS; } /** * Returns the byte stream for JPEG en

文档评论(0)

1亿VIP精品文档

相关文档