5.實現(xiàn)頁面驗證碼刷新
Html代碼
《imgsrc=“kaptcha.jpg”width=“200”id=“kaptchaImage”title=“看不清,點擊換一張”/》
《scripttype=“text/javascript”》
$(function() {
$(‘#kaptchaImage’).click(function() {$(this).attr(‘src’,‘kaptcha.jpg?’ + Math.floor(Math.random() * 100));});
});
《/script》
《br/》《small》看不清,點擊換一張《/small》
《img src=“kaptcha.jpg” width=“200” id=“kaptchaImage” title=“看不清,點擊換一張” /》
《script type=“text/javascript”》
$(function() {
$(‘#kaptchaImage’).click(function() {$(this).attr(‘src’,‘kaptcha.jpg?’ + Math.floor(Math.random() * 100));});
});
《/script》
《br /》《small》看不清,點擊換一張《/small》
注:為了避免瀏覽器的緩存,可以在驗證碼請求url后添加隨機數(shù)
二、Spring mvc項目中使用kaptcha
1.添加captchaProducer bean定義
Xml代碼
《!-- 配置kaptcha驗證碼 --》
《beanid=“captchaProducer”class=“com.google.code.kaptcha.impl.DefaultKaptcha”》
《propertyname=“config”》
《beanclass=“com.google.code.kaptcha.util.Config”》
《constructor-argtype=“java.util.Properties”》
《props》
《propkey=“kaptcha.image.width”》100《/prop》
《propkey=“kaptcha.image.height”》50《/prop》
《propkey=“kaptcha.noise.impl”》com.google.code.kaptcha.impl.NoNoise《/prop》
《propkey=“kaptcha.textproducer.char.string”》0123456789abcdefghijklmnopqrstuvwxyz《/prop》
《propkey=“kaptcha.textproducer.char.length”》4《/prop》
《/props》
《/constructor-arg》
《/bean》
《/property》
《/bean》
《!-- 配置kaptcha驗證碼 --》
《bean id=“captchaProducer” class=“com.google.code.kaptcha.impl.DefaultKaptcha”》
《property name=“config”》
《bean class=“com.google.code.kaptcha.util.Config”》
《constructor-arg type=“java.util.Properties”》
《props》
《prop key=“kaptcha.image.width”》100《/prop》
《prop key=“kaptcha.image.height”》50《/prop》
《prop key=“kaptcha.noise.impl”》com.google.code.kaptcha.impl.NoNoise《/prop》
《prop key=“kaptcha.textproducer.char.string”》0123456789abcdefghijklmnopqrstuvwxyz《/prop》
《prop key=“kaptcha.textproducer.char.length”》4《/prop》
《/props》
《/constructor-arg》
《/bean》
《/property》
《/bean》
評論