没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
kaptcha验证码组件使用简介解析验证码组件使用简介解析
主要介绍了kaptcha验证码组件使用简介解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一
定的参考学习价值,需要的朋友可以参考下
Kaptcha是一个基于SimpleCaptcha的验证码开源项目。
官网地址:http://code.google.com/p/kaptcha/
kaptcha的使用比较方便,只需添加jar包依赖之后简单地配置就可以使用了。kaptcha所有配置都可以通过web.xml来完成,如
果你的项目中使用了Spring MVC,那么则有另外的一种方式来实现。
一、简单的一、简单的jsp-servlet项目项目
1.添加添加jar包依赖包依赖
如果你使用maven来统一管理jar包,则在工程的pom.xml中添加dependency
<!-- kaptcha -->
<dependency>
<groupId>com.google.code.kaptcha</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3.2</version>
</dependency>
如果是非maven管理的项目,则直接在官网下载kaptcha的jar包,然后添加到项目lib库中,下载地址:
http://code.google.com/p/kaptcha/downloads/list
2.配置配置web.xml
上面说了,kaptcha都是在web.xml中配置,我们必须在web.xml中配置kaptcha的servlet,具体如下:
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/kaptcha.jpg</url-pattern>
</servlet-mapping>
其中servlet的url-pattern可以自定义。
kaptcha所有的参数都有默认的配置,如果我们不显示配置的话,会采取默认的配置。
如果要显示配置kaptcha,在配置kaptcha对应的Servlet时,在init-param增加响应的参数配置即可。示例如下:
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
<init-param>
<param-name>kaptcha.image.width</param-name>
<param-value>200</param-value>
<description>Width in pixels of the kaptcha image.</description>
</init-param>
<init-param>
<param-name>kaptcha.image.height</param-name>
<param-value>50</param-value>
<description>Height in pixels of the kaptcha image.</description>
</init-param>
<init-param>
<param-name>kaptcha.textproducer.char.length</param-name>
<param-value>4</param-value>
<description>The number of characters to display.</description>
</init-param>
<init-param>
<param-name>kaptcha.noise.impl</param-name>
<param-value>com.google.code.kaptcha.impl.NoNoise</param-value>
<description>The noise producer.</description>
</init-param>
</servlet>
具体的配置参数参见:http://code.google.com/p/kaptcha/wiki/ConfigParameters
3.页面调用页面调用
资源评论
weixin_38553648
- 粉丝: 5
- 资源: 921
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功