Kaptcha验证码

 

Kaptcha验证码

1】:引包:kaptcha-2.3.2.jar(版本随意)

 

2】:applictionContext.xml中的配置

<!-- 验证码 -->

<bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">  

        <property name="config">  

            <bean class="com.google.code.kaptcha.util.Config">  

                <constructor-arg>  

                    <props>  

                        <prop key="kaptcha.border">no</prop>  

                        <prop key="kaptcha.border.color">105,179,90</prop>  

                        <prop key="kaptcha.textproducer.font.color">red</prop>  

                        <prop key="kaptcha.image.width">250</prop>  

                        <prop key="kaptcha.textproducer.font.size">50</prop>  

                        <prop key="kaptcha.image.height">60</prop>  

                        <prop key="kaptcha.session.key">code</prop>  

                        <prop key="kaptcha.textproducer.char.length">4</prop>  

                        <prop key="kaptcha.textproducer.font.names">宋体,楷体,微软雅黑</prop>  

                    </props>  

                </constructor-arg>  

            </bean>  

        </property>  

</bean>

 

 

3】:jsp中的配置

1img

<img title="看不清,点击刷新" style="float: right; height: 35px;"

       src="/captcha-image" width="150" height="54" id="kaptchaImage" onclick="changeImg()"/>  

(2)changeImg()方法

function changeImg(){

$("#kaptchaImage").hide().attr("src", "/captcha-image?" + Math.floor(Math.random()*100) ).fadeIn();

}

 

 

 

 

Kaptcha验证码

1】:引包:kaptcha-2.3.2.jar(版本随意)

 

2】:applictionContext.xml中的配置

<!-- 验证码 -->

<bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">  

        <property name="config">  

            <bean class="com.google.code.kaptcha.util.Config">  

                <constructor-arg>  

                    <props>  

                        <prop key="kaptcha.border">no</prop>  

                        <prop key="kaptcha.border.color">105,179,90</prop>  

                        <prop key="kaptcha.textproducer.font.color">red</prop>  

                        <prop key="kaptcha.image.width">250</prop>  

                        <prop key="kaptcha.textproducer.font.size">50</prop>  

                        <prop key="kaptcha.image.height">60</prop>  

                        <prop key="kaptcha.session.key">code</prop>  

                        <prop key="kaptcha.textproducer.char.length">4</prop>  

                        <prop key="kaptcha.textproducer.font.names">宋体,楷体,微软雅黑</prop>  

                    </props>  

                </constructor-arg>  

            </bean>  

        </property>  

</bean>

 

 

3】:jsp中的配置

1img

<img title="看不清,点击刷新" style="float: right; height: 35px;"

       src="/captcha-image" width="150" height="54" id="kaptchaImage" onclick="changeImg()"/>  

(2)changeImg()方法

function changeImg(){

$("#kaptchaImage").hide().attr("src", "/captcha-image?" + Math.floor(Math.random()*100) ).fadeIn();

}

 

 

 

posted @ 2016-06-27 17:21  Moka<TI  阅读(223)  评论(0编辑  收藏  举报