java 验证码之 patchca
2015-08-01 13:28
701 查看
patchca
jar下载地址:http://code.google.com/p/patchca/downloads/list
源码下载地址:https://github.com/pusuo/patchca
测试结果:较理想
一、测试
测试后查看项目的根目录
二、springMVC 的使用
jar下载地址:http://code.google.com/p/patchca/downloads/list
源码下载地址:https://github.com/pusuo/patchca
测试结果:较理想
一、测试
测试后查看项目的根目录
public static void main(String[] args) throws IOException { ConfigurableCaptchaService cs = new ConfigurableCaptchaService(); cs.setColorFactory(new SingleColorFactory(new Color(25, 60, 170))); cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory())); FileOutputStream fos = new FileOutputStream("patcha_demo.png"); String validate_code = EncoderHelper.getChallangeAndWriteImage(cs, "png", fos); System.out.println("*****************"+validate_code+"*****************"); fos.close(); }
二、springMVC 的使用
/** * 获取验证码 * * @param request * @param response * @throws IOException */ @RequestMapping(value = "/init/InitRegValCode", produces = "text/plain;charset=UTF-8") @ResponseBody public void InitRegValCode(HttpServletRequest request, HttpServletResponse response) throws IOException { ConfigurableCaptchaService cs = new ConfigurableCaptchaService(); cs.setColorFactory(new SingleColorFactory(new Color(25, 60, 170))); cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory())); RandomFontFactory ff = new RandomFontFactory(); ff.setMinSize(30); ff.setMaxSize(30); RandomWordFactory rwf = new RandomWordFactory(); rwf.setMinLength(4); rwf.setMaxLength(4); cs.setWordFactory(rwf); cs.setFontFactory(ff); cs.setHeight(30); cs.setWidth(140); try { ServletOutputStream stream = response.getOutputStream(); String validate_code = EncoderHelper.getChallangeAndWriteImage(cs, "png", stream); request.getSession().setAttribute("REG_VAL_CODE", validate_code); stream.flush(); stream.close(); } catch (IOException e) { e.printStackTrace(); } }
相关文章推荐
- Struts框架核心工作流程与原理
- eclipse解决乱码问题
- JavaSE----基础语法(数组)
- struts2中的Action
- sublime text 3 编译运行java代码方法
- eclipse中is missing required source folder问题的解决
- java--逻辑运算 位运算
- java--注释方法
- Java-- 变量
- MyEclipse去除网上复制下来的来代码带有的行号
- 修改MyEclipse默认生成的Servlet以及JSP页面
- Java_Web三大框架之Hibernate+jsp+selvect+HQL登入验证
- 解决NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
- MyEclipse 2015优化技巧
- Java手机开发平台 Java ME
- spring入门初体验(4)----事务的传播行为和隔离级别
- java中的接口
- Java Socket编程
- JAVA中堆和栈的区别
- phonegap-环境搭建(1)