当前位置: 首页>>代码示例>>Java>>正文


Java Producer.createImage方法代码示例

本文整理汇总了Java中com.google.code.kaptcha.Producer.createImage方法的典型用法代码示例。如果您正苦于以下问题:Java Producer.createImage方法的具体用法?Java Producer.createImage怎么用?Java Producer.createImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.code.kaptcha.Producer的用法示例。


在下文中一共展示了Producer.createImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:38,代码来源:CaptchaController.java

示例2: 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();
	}
}
 
开发者ID:summerDp,项目名称:dpCms,代码行数:36,代码来源:LoginController.java


注:本文中的com.google.code.kaptcha.Producer.createImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。