• Kaptcha组件实现验证码


    一、生成验证码

    1.导入jar包

    2.写页面

    3.写验证

    4.配置web.xml

    二、详细配置

      1 <init-param>
      2             <description>图片边框,合法值:yes , no</description>
      3             <param-name>kaptcha.border</param-name>
      4             <param-value>yes</param-value>
      5         </init-param>
      6         <init-param>
      7             <description>
      8                 边框颜色,合法值: r,g,b (and optional alpha) 或者
      9                 white,black,blue.
     10             </description>
     11             <param-name>kaptcha.border.color</param-name>
     12             <param-value>black</param-value>
     13         </init-param>
     14         <init-param>
     15             <description>边框厚度,合法值:>0</description>
     16             <param-name>kaptcha.border.thickness</param-name>
     17             <param-value>1</param-value>
     18         </init-param>
     19         <init-param>
     20             <description>图片宽 200</description>
     21             <param-name>kaptcha.image.width</param-name>
     22             <param-value>200</param-value>
     23         </init-param>
     24         <init-param>
     25             <description>图片高 50</description>
     26             <param-name>kaptcha.image.height</param-name>
     27             <param-value>50</param-value>
     28         </init-param>
     29         <init-param>
     30             <description>图片实现类</description>
     31             <param-name>kaptcha.producer.impl</param-name>
     32             <param-value>
     33                 com.google.code.kaptcha.impl.DefaultKaptcha
     34             </param-value>
     35         </init-param>
     36         <init-param>
     37             <description>文本实现类</description>
     38             <param-name>kaptcha.textproducer.impl</param-name>
     39             <param-value>
     40                 com.google.code.kaptcha.text.impl.DefaultTextCreator
     41             </param-value>
     42         </init-param>
     43         <init-param>
     44             <description>文本集合,验证码值从此集合中获取</description>
     45             <param-name>kaptcha.textproducer.char.string</param-name>
     46             <param-value>1234567890</param-value>
     47         </init-param>
     48         <init-param>
     49             <description>验证码长度 5</description>
     50             <param-name>kaptcha.textproducer.char.length</param-name>
     51             <param-value>2</param-value>
     52         </init-param>
     53         <init-param>
     54             <description>字体 Arial, Courier</description>
     55             <param-name>kaptcha.textproducer.font.names</param-name>
     56             <param-value>Arial, Courier</param-value>
     57         </init-param>
     58         <init-param>
     59             <description>字体大小 40px.</description>
     60             <param-name>kaptcha.textproducer.font.size</param-name>
     61             <param-value>40</param-value>
     62         </init-param>
     63         <init-param>
     64             <description>
     65                 字体颜色,合法值: r,g,b 或者 white,black,blue.
     66             </description>
     67             <param-name>kaptcha.textproducer.font.color</param-name>
     68             <param-value>black</param-value>
     69         </init-param>
     70         <init-param>
     71             <description>文字间隔 2</description>
     72             <param-name>kaptcha.textproducer.char.space</param-name>
     73             <param-value>2</param-value>
     74         </init-param>
     75         <init-param>
     76             <description>干扰实现类</description>
     77             <param-name>kaptcha.noise.impl</param-name>
     78             <param-value>
     79                 <!-- com.google.code.kaptcha.impl.NoNoise -->
     80                 com.google.code.kaptcha.impl.DefaultNoise
     81             </param-value>
     82         </init-param>
     83         <init-param>
     84             <description>
     85                 干扰颜色,合法值: r,g,b 或者 white,black,blue.
     86             </description>
     87             <param-name>kaptcha.noise.color</param-name>
     88             <param-value>black</param-value>
     89         </init-param>
     90         <init-param>
     91             <description>
     92                 图片样式: 水纹com.google.code.kaptcha.impl.WaterRipple
     93                 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy
     94                 阴影com.google.code.kaptcha.impl.ShadowGimpy
     95             </description>
     96             <param-name>kaptcha.obscurificator.impl</param-name>
     97             <param-value>
     98                 com.google.code.kaptcha.impl.WaterRipple
     99             </param-value>
    100         </init-param>
    101         <init-param>
    102             <description>背景实现类</description>
    103             <param-name>kaptcha.background.impl</param-name>
    104             <param-value>
    105                 com.google.code.kaptcha.impl.DefaultBackground
    106             </param-value>
    107         </init-param>
    108         <init-param>
    109             <description>背景颜色渐变,开始颜色</description>
    110             <param-name>kaptcha.background.clear.from</param-name>
    111             <param-value>green</param-value>
    112         </init-param>
    113         <init-param>
    114             <description>背景颜色渐变,结束颜色</description>
    115             <param-name>kaptcha.background.clear.to</param-name>
    116             <param-value>white</param-value>
    117         </init-param>
    118         <init-param>
    119             <description>文字渲染器</description>
    120             <param-name>kaptcha.word.impl</param-name>
    121             <param-value>
    122                 com.google.code.kaptcha.text.impl.DefaultWordRenderer
    123             </param-value>
    124         </init-param>
    125         <init-param>
    126             <description>
    127                 session中存放验证码的key键
    128             </description>
    129             <param-name>kaptcha.session.key</param-name>
    130             <param-value>KAPTCHA_SESSION_KEY</param-value>
    131         </init-param>
    132         <init-param>
    133             <description>
    134                 The date the kaptcha is generated is put into the
    135                 HttpSession. This is the key value for that item in the
    136                 session.
    137             </description>
    138             <param-name>kaptcha.session.date</param-name>
    139             <param-value>KAPTCHA_SESSION_DATE</param-value>
    140         </init-param>

    三、算式验证码的实现——>重写KapthaServlet类

    1. 获取随机值,结果相加

    2.将计算公式写到验证码图片中

    3.将相加结果放在session中

  • 相关阅读:
    C语言面向对象编程(五):单链表实现(转)
    pthread_barrier_init,pthread_barrier_wait简介(转)
    Linux信号(signal) 机制分析(转)
    Linux 进程间通信 --- 信号通信 --- signal --- signal(SIGINT, my_func); --- 按键驱动异步通知(转)
    Linux 多线程环境下 进程线程终止函数小结(转)
    批量杀进程 ps awk grep
    C++中的INL(转)
    gdb调试多进程和多线程命令(转)
    转: 基于netty+ protobuf +spring + hibernate + jgroups开发的游戏服务端
    转:全栈工程师的知识栈列表
  • 原文地址:https://www.cnblogs.com/olivegyr/p/7402861.html
Copyright © 2020-2023  润新知