Java中使用patchca生成超炫的验证码
官网:http://code.google.com/p/patchca/
/**
*验证码
*
*@paramwidth图片宽度
*@paramheight图片高度
*@paramnumber验证码数量
*/
@RequestMapping(value={"/captcha"})
publicvoidcaptcha(HttpServletRequestrequest,
HttpServletResponseresponse,@RequestParam("w")intwidth,@RequestParam("h")intheight,@RequestParam("n")intnumber)throwsIOException{
ConfigurableCaptchaServicecs=newConfigurableCaptchaService();
cs.setColorFactory(newSingleColorFactory(newColor(25,60,170)));
cs.setFilterFactory(newCurvesRippleFilterFactory(cs.getColorFactory()));
RandomFontFactoryff=newRandomFontFactory();
ff.setMinSize(30);
ff.setMaxSize(30);
RandomWordFactoryrwf=newRandomWordFactory();
rwf.setMinLength(number);
rwf.setMaxLength(number);
cs.setWordFactory(rwf);
cs.setFontFactory(ff);
cs.setHeight(height);
cs.setWidth(width);
response.setContentType("image/png");
response.setHeader("Cache-Control","no-cache,no-store");
response.setHeader("Pragma","no-cache");
longtime=System.currentTimeMillis();
response.setDateHeader("Last-Modified",time);
response.setDateHeader("Date",time);
response.setDateHeader("Expires",time);
ServletOutputStreamstream=response.getOutputStream();
Stringvalidate_code=EncoderHelper.getChallangeAndWriteImage(cs,
"png",stream);
Subjectsubject=SecurityUtils.getSubject();
subject.getSession().setAttribute(formAuthenticationFilter.getCaptchaParam(),validate_code);
stream.flush();
stream.close();
}
以上所述是小编给大家介绍的Java中使用patchca生成超炫的验证码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!