标签:request val res ica throws setattr png put response
图形验证码生成方法
@RequestMapping("/verification")
public void valicode(HttpServletResponse response, HttpSession session) throws Exception {
//利用图片工具生成图片
//第一个参数是生成的验证码,第二个参数是生成的图片
Object[] objs = VerifyUtil.createImage();
String codeKey = "IMAGECODE";
//将验证码存入Session
session.setAttribute(codeKey, objs[0]);
//将图片输出给浏览器
BufferedImage image = (BufferedImage) objs[1];
response.setContentType("image/png");
OutputStream os = response.getOutputStream();
ImageIO.write(image, "png", os);
}
标签:request val res ica throws setattr png put response
原文地址:https://www.cnblogs.com/lucl/p/12199758.html