博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC整合kaptcha(验证码功能)
阅读量:4488 次
发布时间:2019-06-08

本文共 1812 字,大约阅读时间需要 6 分钟。

一、依赖

com.github.penggle
kaptcha
2.3.2

二、springmvc配置文件

yes
105,179,90
blue
125
45
45
code
4
宋体,楷体,微软雅黑

三、编码

1.后端

controler类中:    @Autowired    private Producer captchaProducer = null;    @RequestMapping(value = "captcha")    public void getKaptchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception {        HttpSession session = request.getSession();        response.setDateHeader("Expires", 0);        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");        response.addHeader("Cache-Control", "post-check=0, pre-check=0");        response.setHeader("Pragma", "no-cache");        response.setContentType("image/jpeg");        //生成验证码        String capText = captchaProducer.createText();        session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);        //向客户端写出        BufferedImage bi = captchaProducer.createImage(capText);        ServletOutputStream out = response.getOutputStream();        ImageIO.write(bi, "jpg", out);        try {            out.flush();        } finally {            out.close();        }    }

2.前端

3.效果图

542859-20170803223426709-1361521091.jpg

转载于:https://www.cnblogs.com/moonlightL/p/7282469.html

你可能感兴趣的文章
Siamese Network简介
查看>>
svg学习(三)rect
查看>>
博客园博文生成章节目录
查看>>
ruby 模块 的引入
查看>>
CI Weekly #21 | iOS 持续集成快速入门指南
查看>>
xml 校验
查看>>
Jquery获取输入框属性file,ajax传输后端,下载图片
查看>>
深入浅出Visual_C动态链接库(Dll)编程(宋宝华)----整理(word)
查看>>
docker运行环境安装-后续步骤(二)
查看>>
Python学习——02-Python基础——【3集合与函数】
查看>>
NPOI导出excel表格应用
查看>>
tensorflow从入门到放弃-0
查看>>
解锁scott用户
查看>>
多态的理解
查看>>
AspNet Core 发布到Linux系统和发布IIS 注意项
查看>>
Windows添加.NET Framework 3.0 NetFx3 失败 - 状态为:0x800f0950
查看>>
隐藏显示终端的光标(shell echo,linux c printf)
查看>>
SQL Server 存储过程
查看>>
JSP 标准标签库(JSTL)(JSP Standard Tag Library)
查看>>
导入项目遇到的问题: Some projects cannot be imported because they already exist in the workspace....
查看>>