我们使用SimpleCaptcha http://simplecaptcha.sourceforge.net/在注册表单中创建验证码(在Tomcat上运行)
我们使用以下命令创建验证码:
Captcha captcha = new Captcha.Builder(300, 57).build(); 验证码显示如下:

但是当我向验证码添加更多选项时,比如Captcha captcha = new Captcha.Builder(300, 57).addNoise().build();,它仍然以相同的方式显示,没有噪音。我尝试了更多的选项,但仍然得到了相同的结果。
有人知道为什么会发生这种事吗?
谢谢,
库尔特
发布于 2011-06-09 06:39:32
我尝试了上面的代码(使用java1.6版本),它没有任何结果。原因是您没有.addText()。(我本想写这篇评论,但我没有足够的名气)。这表明你上面的代码并不是你的实际代码,也许你在发帖的时候忘了什么。
下面是我使用的有效方法:
public class MyCaptchaServlet extends SimpleCaptchaServlet
{
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
Captcha captcha = new Captcha.Builder(120,40).addText().addBorder().gimp().addBackground(new GradiatedBackgroundProducer()).build();
CaptchaServletUtil.writeImage(response, captcha.getImage());
request.getSession().setAttribute(Captcha.NAME, captcha);
}
}在.build()之前添加.addNoise()确实会显示出问题。
https://stackoverflow.com/questions/5856793
复制相似问题