下载地址:
http://code.google.com/p/kaptcha/
生成图片 jsp页面
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="com.yongmail.web.ImageCode"%>
<%@page import="com.yongmail.utils.ToolUtil"%>
<%
String sid = request.getParameter("sid");
if (ToolUtil.isEmpty(sid))
return;
out.clear();
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 = ImageCode.getProducer().createText();
// store the text in the session
request.getSession().setAttribute(sid, capText);
// create the image with the text
BufferedImage bi = ImageCode.getProducer().createImage(capText);
ServletOutputStream outStr = response.getOutputStream();
// write the data out
ImageIO.write(bi, "jpg", outStr);
try {
outStr.flush();
} finally {
outStr.close();
}
%>
显示页面
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@page import="com.yongmail.utils.TimeUtil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>申请账号</title>
</head>
<%
String id = request.getSession().getId();
String countId = TimeUtil.genId();
%>
<body>
<form action="submitApply.jsp?countId=<%=countId %>" method="post">
<input name="" type="text" />
<input type="submit" name="Submit" value="提交" />
</form>
<% out.print("<img src=\"getCode.jsp?sid="+id+"_"+countId+"\"/>"); %>
</body>
</html>
提交后取得验证码示例
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
</head>
<body>
<%
String countId = request.getParameter("countId");
System.out.println((String)request.getSession().getAttribute(request.getSession().getId()+"_"+countId));
%>
</body>
</html>
ImageCode类
import java.util.Properties;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.util.Config;
public class ImageCode {
private static Producer kaptchaProducer = null;
private static Properties props = new Properties();
private static Config config = new Config(props);
public static Producer getProducer(){
if(kaptchaProducer == null){
kaptchaProducer = (Producer) config.getProducerImpl();
}
return kaptchaProducer;
}
}
分享到:
相关推荐
google的Kaptcha生成验证码,附件有jar资源和使用Demo 一款可以各种配置显示方式的验证码
主要介绍了java下使用kaptcha生成验证码,感兴趣的小伙伴们可以参考一下
使用Kaptcha生成随机码的一个demo
使用kaptcha生成验证码的作用:进行人机校验--防止机器脚本,自动大量注册用户。 1.Kaptcha是谷歌开源的可高度配置的实用验证码生成工具。 2.通过Kaptcha可阻拦大多数机器人脚本操作。 3.kaptcha典型殷勇于注册、...
kaptcha生成验证码的作用:进行人机校验--防止机器脚本自动大量注册用户。 1、Kaptcha是谷歌开源的可高度配置的实用验证码生成工具。 2、过Kaptcha可阻拦大多数机器人脚本操作。 3、kaptcha典型殷用于注册、登录、...
vue+springboot+redis+kaptcha实现登录页验证码
Java使用kaptcha实现验证码功能必备jar包,使用简单,web.xml中配置即用。 Java使用kaptcha实现验证码功能必备jar包,使用简单,web.xml中配置即用。
kaptcha 图片验证码 springMVC project demo
本篇文章主要介绍了spring mvc 使用kaptcha生成验证码实例,详细的介绍了使用Kaptcha 生成验证码的步骤,有兴趣的可以了解一下
编译器版本:IntelliJ IDEA 2020.3.2 x64 JDK版本:java 1.8.0_111 SpringBoot集成Kaptcha验证码生成器快速入门Demo,演示Kaptcha验证码生成器后端代码和前端测试页面
用来生成验证码的工具类,已有完整的demo,按照样例来使用即可~
该资源是谷歌 kaptcha jar包,以及该jar包的使用说明,这是谷歌自动生成图片验证码,大大节省的开发时间,用起来比较简单,已过时,但仍然可以使用,喜欢的小伙伴就下载吧,有什么不懂的地方可以咨询博主。
kaptcha-2.3.2.jar,一个java开源的验证码工具包,kaptcha是一个非常实用的验证码生成工具。有了它,你可以生成各种样式的验证码,因为它是可配置的,有需要的赶快下载吧!
kaptcha验证码配置的3种方式 参照本演示项目
验证码在很多地方都会使用到,本分享是自己在做验证码功能的时候总结的一些经验,是基于谷歌kaptcha来做的,验证码的效果是,可以自定义字符范围,可以自定义背景效果,自定义字体等。总之,根据参数,都可以实现...
主要介绍了spring整合kaptcha验证码的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
本项目是一个安卓获取随机验证码的小例子,可以随机生成4位数字的验证码并且绘制有燥点和干扰线,绘制出的数字很小,如果视力不好估计看不见。不过如果想OCR识别肯定是很难的,有用到的朋友自己下载研究吧。
google kaptcha-2.3.2.jar验证码的jar包,google把生成验证码的操作基本的封装好了,使用起来很方便。
自己实现用idea实现了下google的kaptcha验证码,挺好用的,使用简单方便,希望能够帮助到大家
主要为大家详细介绍了javaWeb使用Kaptcha组件生成验证码的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下