仿牛客社区开发(登录模块-生成验证码)
概述
kaptcha依赖
<!-- https://mvnrepository.com/artifact/com.github.penggle/kaptcha -->
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3.2</version>
</dependency>
kaptcha配置类 - KaptchaConfig
实例化一个默认的DefaultKaptcha,之后set配置config,配置通过properties保存,可直接在xml配置文件中,然后引入获取配置
controller - /kaptcha
在LoginController中写响应/kaptcha请求的接口,将验证码存入session,通过输出流输出给浏览器
前端 - login.html
CONTEXT_PATH 声明在 global.js 中是 /community ,之后加一个随机数参数,用于欺骗浏览器,让它认为多次请求的路径url不一样(如果多次请求的url一样,那么浏览器可能会拒绝访问),之后通过选择器定位标签,改path