@Action("/validimg")
public String validimg() throws Exception {
genernateCaptchaImage();
return null;
}
protected void genernateCaptchaImage() 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();
LOGGER.info("当前生产验证码的sessionId为: "+captchaId);
BufferedImage challenge = (BufferedImage) CaptchaServiceSingleton.getInstance().getChallengeForID(
captchaId, request.getLocale());
ImageIO.write(challenge, "jpg", out);
out.flush();
} catch (CaptchaServiceException e) {
} finally {
out.close();
}
}
/**
* JCaptcha的单例
*
* @author fuxingxign
*/
public class CaptchaServiceSingleton {
private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService(
new FastHashMapCaptchaStore(), new RdImageEngine(), 180, 100000, 75000); /*
* private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService( new
* FastHashMapCaptchaStore(), new GMailEngine(), 180, 100000 , 75000);
*/
public static ImageCaptchaService getInstance() {
return instance;
}
}

import java.awt.Color;
import java.awt.Font; import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
import com.octo.captcha.component.image.color.RandomRangeColorGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
import com.octo.captcha.component.image.textpaster.RandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory; public class RdImageEngine extends ListImageCaptchaEngine {
@Override
protected void buildInitialFactories() {
WordGenerator wgen = new RandomWordGenerator("abcdefghijklmnopqrstuvwxyz");
RandomRangeColorGenerator cgen = new RandomRangeColorGenerator(new int[] { 0, 100 }, new int[] { 0, 100 },
new int[] { 0, 100 });
TextPaster textPaster = new RandomTextPaster(Integer.valueOf(4),Integer.valueOf(4), cgen, true);
BackgroundGenerator backgroundGenerator = new UniColorBackgroundGenerator(Integer.valueOf(80), Integer.valueOf(37),
Color.WHITE);
Font[] fontsList = new Font[] { new Font("Arial", 0, 12), new Font("Tahoma", 0, 12),
new Font("Verdana", 0, 12), };
FontGenerator fontGenerator = new RandomFontGenerator(Integer.valueOf(26),Integer.valueOf(26), fontsList); WordToImage wordToImage = new ComposedWordToImage(fontGenerator, backgroundGenerator, textPaster);
this.addFactory(new GimpyFactory(wgen, wordToImage));
} }

最新文章

  1. grape动态PHP结构(一)——目录结构与配置文件
  2. nvm诡异的报错
  3. Ansible常用模块
  4. 【bzoj2060】[Usaco2010 Nov]Visiting Cows拜访奶牛
  5. TOMCAT如何建立两个端口或服务
  6. 推荐几个的chorme的扩展程序
  7. Linux Apache和Nginx网络模型详解
  8. IT国家重点实验室
  9. 微信分享jssdk config:invalid signature 签名错误
  10. LVS+Keepalived实现高可用负载均衡(转)
  11. 关于浏览器和HTTP协议
  12. haproxy安装配置for mysql负载均衡(ubantu)
  13. 分布式服务跟踪及Spring Cloud的实现
  14. 转://oracle Wallet在expdp/impdp中使用场景
  15. 基于asp.net的excel导入导出
  16. 关于jquery中on绑定click事件在苹果手机失效的问题
  17. day 26
  18. SITEMAP放到独立的文件上面
  19. ubuntu14.04 64位JDK安装
  20. ES6学习笔记(四)-数值扩展

热门文章

  1. [译]如何禁止Requests库的log日志信息呢?
  2. 阻塞&&非阻塞
  3. objective-c runtime 开发详情
  4. python带header
  5. hihoCoder 1015KMP
  6. HDU2669 Romantic
  7. 行为型设计模式之状态模式(State)
  8. 信息竞赛程序卡时_C++
  9. vue 项目 webstrom IDE格式化代码规则遵循eslint设置
  10. EVERYTHING 1.3.4参数