java验证码组件kaptcha使用方法

使用方法

项目中导入kaptcha-2.3.jar包

在web.xml里面新增: 

复制代码 代码如下:


   
        Kaptcha
        com.google.code.kaptcha.servlet.KaptchaServlet
                  
            kaptcha.producer.impl
            com.google.code.kaptcha.impl.DefaultKaptcha
       

                  
                            kaptcha.textproducer.font.color
                            black
                  

                  
                            kaptcha.textproducer.char.space
                            10
                  

                  
                            kaptcha.border
                            no
                  

                  
                            kaptcha.border.thickness
                            0
                  

                  
                            kaptcha.textproducer.font.size
                            35
                  

                  
                            kaptcha.textproducer.char.length
                            4
                  

                  
            kaptcha.image.width
            150
       

       
            kaptcha.image.height
            50
       

       
                            kaptcha.background.clear.from
                            255,255,255
                  

                  
                            kaptcha.background.clear.to
                            255,255,255
                  

                  
            kaptcha.textproducer.char.string
            0123456789
       

       
            kaptcha.textproducer.font.names
            Arial Black
       

        
            kaptcha.noise.impl
            com.google.code.kaptcha.impl.NoNoise
       

   

   
        Kaptcha
        /kaptcha.jpg

在页面上新增

复制代码 代码如下:

点击更换验证码
function refresh() {
                  document.getElementById('img').src="kaptcha.jpg?"+Math.random();
}

在action里获取验证码ID:

复制代码 代码如下:

request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);

你可能感兴趣的:(java验证码组件kaptcha使用方法)