步骤一导入kaptcha的jar包
步骤二在xml中配置servlet
<servlet>
<servlet-name>KaptchaServlet</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
<init-param>
<param-name>kaptcha.border.color</param-name>
<param-value>red</param-value>
</init-param>
<init-param>
<param-name>kaptcha.textproducer.char.string</param-name>
<param-value>abcdefg</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>KaptchaServlet</servlet-name>
<url-pattern>/kaptcha.jpg</url-pattern>
</servlet-mapping>
步骤三前端写代码测试
<img src="kaptcha.jpg"/>
最后重启tomcat就能看到啦
分界线 这里是可以选配
public static final String KAPTCHA_SESSION_KEY = "KAPTCHA_SESSION_KEY";
public static final String KAPTCHA_SESSION_DATE = "KAPTCHA_SESSION_DATE";
public static final String KAPTCHA_SESSION_CONFIG_KEY = "kaptcha.session.key";
public static final String KAPTCHA_SESSION_CONFIG_DATE = "kaptcha.session.date";
public static final String KAPTCHA_BORDER = "kaptcha.border";
public static final String KAPTCHA_BORDER_COLOR = "kaptcha.border.color";
public static final String KAPTCHA_BORDER_THICKNESS = "kaptcha.border.thickness";
public static final String KAPTCHA_NOISE_COLOR = "kaptcha.noise.color";
public static final String KAPTCHA_NOISE_IMPL = "kaptcha.noise.impl";
public static final String KAPTCHA_OBSCURIFICATOR_IMPL = "kaptcha.obscurificator.impl";
public static final String KAPTCHA_PRODUCER_IMPL = "kaptcha.producer.impl";
public static final String KAPTCHA_TEXTPRODUCER_IMPL = "kaptcha.textproducer.impl";
public static final String KAPTCHA_TEXTPRODUCER_CHAR_STRING = "kaptcha.textproducer.char.string";
public static final String KAPTCHA_TEXTPRODUCER_CHAR_LENGTH = "kaptcha.textproducer.char.length";
public static final String KAPTCHA_TEXTPRODUCER_FONT_NAMES = "kaptcha.textproducer.font.names";
public static final String KAPTCHA_TEXTPRODUCER_FONT_COLOR = "kaptcha.textproducer.font.color";
public static final String KAPTCHA_TEXTPRODUCER_FONT_SIZE = "kaptcha.textproducer.font.size";
public static final String KAPTCHA_TEXTPRODUCER_CHAR_SPACE = "kaptcha.textproducer.char.space";
public static final String KAPTCHA_WORDRENDERER_IMPL = "kaptcha.word.impl";
public static final String KAPTCHA_BACKGROUND_IMPL = "kaptcha.background.impl";
public static final String KAPTCHA_BACKGROUND_CLR_FROM = "kaptcha.background.clear.from";
public static final String KAPTCHA_BACKGROUND_CLR_TO = "kaptcha.background.clear.to";
public static final String KAPTCHA_IMAGE_WIDTH = "kaptcha.image.width";
public static final String KAPTCHA_IMAGE_HEIGHT = "kaptcha.image.height";