java一个中文的验证码程序_kaptcha中文验证码

Java类

目前只支持在windows上运行,因为linux上没有对应的字体,

使用默认字体,可以迁移到任意服务器。

class="java" name="code">

package com.xxx.catcha;

import java.awt.image.BufferedImage;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.Properties;

import javax.imageio.ImageIO;

import com.google.code.kaptcha.Producer;

import com.google.code.kaptcha.util.Config;

/**

* Hello world!

*

*/

public class App

{

public static void main( String[] args ) throws IOException

{

Properties props = new Properties();

//可选字符

props.put("kaptcha.textproducer.char.string", "0123456789一二三四五六七八九");

//验证码字体

props.put("kaptcha.textproducer.font.names", "华文彩云");

//验证码字数

props.put("kaptcha.textproducer.char.length", "4");

Config config = new Config(props);

Producer producer = (Producer)config.getProducerImpl();

String capText = producer.createText();

BufferedImage bi = producer.createImage(capText);

FileOutputStream out = new FileOutputStream("kaptcha.jpg");

ImageIO.write(bi, "jpg", out);

}

}

pom.xml文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.xxx

catcha

0.0.1-SNAPSHOT

jar

catcha

http://maven.apache.org

UTF-8

com.github.axet

kaptcha

0.0.9

junit

junit

3.8.1

test

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值