SpringMVC中使用patchca生成验证码
来源:互联网 发布:手机号码定位软件 编辑:程序博客网 时间:2024/06/04 18:12
一、页面直接使用img标签
二、主要代码如下:
@RequestMapping@Controllerpublic class IdentifyCodeController {private static ConfigurableCaptchaService ccs = new ConfigurableCaptchaService();private static Random random = new SecureRandom();static{ccs.setColorFactory(new ColorFactory() {@Overridepublic Color getColor(int n) {int[] c = new int[3];int i = random.nextInt(c.length);for(int j=0;j<c.length;j++){if(j == i){c[j] = random.nextInt(71);}else{c[j] = random.nextInt(256);}}return new Color(c[0], c[1], c[2]);} });RandomWordFactory rwf = new RandomWordFactory();rwf.setCharacters("23456789abcdefghigkmnpqrstuvwxyzABCDEFGHIGKLMNPQRSTUVWXYZ");rwf.setMaxLength(4);rwf.setMinLength(4);ccs.setWordFactory(rwf);}@RequestMapping(value="/verify.html")public void verifyCode(HttpServletRequest request,HttpServletResponse response) throws IOException{switch(random.nextInt(5)){case 0:ccs.setFilterFactory(new CurvesRippleFilterFactory(ccs.getColorFactory()));break;case 1:ccs.setFilterFactory(new MarbleRippleFilterFactory());break;case 2:ccs.setFilterFactory(new DoubleRippleFilterFactory());break;case 3:ccs.setFilterFactory(new WobbleRippleFilterFactory());break;case 4:ccs.setFilterFactory(new DiffuseRippleFilterFactory());break;}HttpSession session = request.getSession(false);if(session == null){session = request.getSession();}setResponseHeaders(response);String token = EncoderHelper.getChallangeAndWriteImage(ccs, "png", response.getOutputStream());session.setAttribute("captchaToken", token);System.out.println("当前的SessionID=" + session.getId() + ",验证码=" + token);}protected void setResponseHeaders(HttpServletResponse response){response.setContentType("image/png");response.setHeader("Cache-Control", "no-cache, no-store"); response.setHeader("Pragma", "no-cache"); long time = System.currentTimeMillis(); response.setDateHeader("Last-Modified", time); response.setDateHeader("Date", time); response.setDateHeader("Expires", time);}}
三、使用jar见附件
0 0
- SpringMVC中使用patchca生成验证码
- 使用patchca生成验证码
- Java使用patchca生成验证码
- Java使用patchca生成验证码
- 利用patchca生成验证码
- 使用开源项目patchca生成验证码
- 使用开源项目patchca生成验证码
- patchca生成超炫的验证码
- Java验证码 patchca使用配置方法
- patchca整合Spring MVC生成超炫的验证码
- patchca整合Spring MVC生成超炫的验证码
- patchca整合Spring MVC生成超炫的验证码
- patchca整合Spring MVC生成漂亮的验证码
- patchca整合Spring MVC生成超炫的验证码
- jfinal + Patchca 验证码实现
- java 验证码之 patchca
- SpringMVC项目中使用kaptcha生成验证码
- springMVC中验证码生成工具kaptcha的使用
- mysql ”Invalid use of null value“ 解决方法
- 设计模式之工厂方法和抽象工厂
- Android Studio代码折叠
- MD5加密和解密,可作为工具类模块保存
- PHP单元测试phpunit
- SpringMVC中使用patchca生成验证码
- RFS连接sqlite和mysql数据库方法与脚本实例
- SpringMVC总结之配置
- iOS解决导航栏标题向右偏移问题
- 多线程中的lua同步问题
- Android自定义View获取background的颜色和图片
- 网站sql注入漏洞修复
- 微信官方jssdk Demo
- c++读取txt文件到string