<dependencies> <dependency> <groupId>com.github.whvcse</groupId> <artifactId>easy-captcha</artifactId> <version>1.6.2</version> </dependency></dependencies>
@Controllerpublic class CaptchaController { @RequestMapping("/captcha") public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception { CaptchaUtil.out(request, response); }}
<img src="/captcha" width="130px" height="48px" />
@Controllerpublic class LoginController { @PostMapping("/login") public JsonResult login(String username,String password,String verCode){ if (!CaptchaUtil.ver(verCode, request)) { CaptchaUtil.clear(request); // 清除session中的验证码 return JsonResult.error("验证码不正确"); } } }
文章有问题?点此查看未经处理的缓存