本文整理汇总了Java中com.google.code.kaptcha.Producer类的典型用法代码示例。如果您正苦于以下问题:Java Producer类的具体用法?Java Producer怎么用?Java Producer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Producer类属于com.google.code.kaptcha包,在下文中一共展示了Producer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureCaptcha
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
void configureCaptcha(Binder binder) {
DefaultKaptcha producer = new DefaultKaptcha();
Properties properties;
try {
properties = ActionConfig.loadPropertyFile("captcha.properties");
Config config = new Config(properties);
producer.setConfig(config);
} catch (RuntimeException e) {
log.warn(e.getMessage());
}
binder.bind(Producer.class).toInstance(producer);
binder.bind(KaptchaExtend.class).toInstance(new KaptchaExtend());
}
示例2: execute
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
response.setDateHeader("Expires", 0);
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control","no-store, no-cache, must-revalidate");
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
// return a jpeg
response.setContentType("image/jpeg");
int width=defaultWidth;
int height=defaultHeight;
String key=defaultSessionKey;
if(StringUtils.isNotEmpty(request.getParameter("width"))){
width=Integer.valueOf(request.getParameter("width"));
}
if(StringUtils.isNotEmpty(request.getParameter("height"))){
height=Integer.valueOf(request.getParameter("height"));
}
if(StringUtils.isNotEmpty(request.getParameter("key"))){
key=request.getParameter("key");
}
Producer captchaProducer = this.getProducer(width, height);
String capText = captchaProducer.createText();
request.getSession().setAttribute(key,capText);
// create the image with the text
BufferedImage bi = captchaProducer.createImage(capText);
ServletOutputStream out = response.getOutputStream();
try {
// write the data out
ImageIO.write(bi,"jpg", out);
out.flush();
} finally {
out.close();
}
}
示例3: getProducer
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
private Producer getProducer(int width, int height) {
DefaultKaptcha kaptcha = new DefaultKaptcha();
Properties prop = new Properties();
prop.put(Constants.KAPTCHA_IMAGE_WIDTH,String.valueOf(width));
prop.put(Constants.KAPTCHA_IMAGE_HEIGHT,String.valueOf(height));
prop.put(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, 5);
prop.put(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE,"6");
prop.put(
Constants.KAPTCHA_BACKGROUND_CLR_FROM,
String.valueOf(RandomUtils.nextInt(255)) + ","
+ RandomUtils.nextInt(255) + ","
+ RandomUtils.nextInt(255));
prop.put(
Constants.KAPTCHA_BACKGROUND_CLR_TO,
String.valueOf(RandomUtils.nextInt(255)) + ","
+ RandomUtils.nextInt(255) + ","
+ RandomUtils.nextInt(255));
prop.put(
Constants.KAPTCHA_NOISE_COLOR,
String.valueOf(RandomUtils.nextInt(255)) + ","
+ RandomUtils.nextInt(255) + ","
+ RandomUtils.nextInt(255));
prop.put(
Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR,
String.valueOf(RandomUtils.nextInt(255)) + ","
+ RandomUtils.nextInt(255) + ","
+ RandomUtils.nextInt(255));
prop.put(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, String.valueOf(height-14));
prop.put(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING,
"123456789abcdefghijkmnlpqrstuvwxyz");
Config config = new Config(prop);
kaptcha.setConfig(config);
return kaptcha;
}
示例4: captcha
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
/**
* 获取登录的图片验证码
*/
@RequestMapping(value = "/imgcode", method = RequestMethod.GET)
public void captcha(HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException {
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
Producer captchaProducer = KaptchaProducerAgency.getKaptchaProducerExample();
response.setDateHeader("Expires", 0);
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control",
"no-store, no-cache, must-revalidate");
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
// return a jpeg
response.setContentType("image/jpeg");
// create the text for the image
String capText = captchaProducer.createText();
log.debug("******************验证码是: " + capText + "******************");
// store the text in the session
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText );
// create the image with the text
BufferedImage bi = captchaProducer.createImage(capText);
ServletOutputStream out = response.getOutputStream();
// write the data out
ImageIO.write(bi, "jpg", out);
try {
out.flush();
} finally {
out.close();
}
}
示例5: getProducerImpl
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
/** */
public Producer getProducerImpl()
{
String paramName = Constants.KAPTCHA_PRODUCER_IMPL;
String paramValue = this.properties.getProperty(paramName);
Producer producer = (Producer) this.helper.getClassInstance(paramName, paramValue, new DefaultKaptcha(), this);
return producer;
}
示例6: setCaptchaProducer
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
@Autowired
public void setCaptchaProducer(Producer captchaProducer) {
this.captchaProducer = captchaProducer;
}
示例7: setCaptchaProducer
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
@Inject
public void setCaptchaProducer(final Producer captchaProducer) {
this.captchaProducer = captchaProducer;
}
示例8: setCaptchaProducer
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
public void setCaptchaProducer(Producer captchaProducer) {
this.captchaProducer = captchaProducer;
}
示例9: getCaptchaProducer
import com.google.code.kaptcha.Producer; //导入依赖的package包/类
public Producer getCaptchaProducer() {
return captchaProducer;
}