引入依赖
cn.hutool hutool-all5.7.5
protected void captcha(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
LineCaptcha lineCaptcha = new LineCaptcha(260, 100, 4, 5);
String code = lineCaptcha.getCode();
//将验证码存入 session
req.getSession().setAttribute("captcha",code);
//将验证码图片响应给前端页面
ServletOutputStream outputStream = resp.getOutputStream();
lineCaptcha.write(outputStream);
outputStream.close();
}



