Java Simple Captcha Builder 放在哪里?

发布于 2024-08-18 12:19:12 字数 397 浏览 5 评论 0原文

我是 java/java servlet 的新手。我需要 simpleCaptcha 作为表单,使用 html 和 javaservlet 作为代码。参考http://simplecaptcha.sourceforge.net/extending.html

Captcha captcha = new Captcha.Builder(200, 50)
    .addText()
    .addBackground()
    .addNoise()
    .gimp()
    .addBorder()
    .build(); // Required. 

为了在 html 上创建验证码,我应该把这段代码放在哪里(java servlet)?

非常感谢。

I am a newbie at java/java servlet. I need the simpleCaptcha for a form, using html and javaservlet for the code. With reference to http://simplecaptcha.sourceforge.net/extending.html.

Captcha captcha = new Captcha.Builder(200, 50)
    .addText()
    .addBackground()
    .addNoise()
    .gimp()
    .addBorder()
    .build(); // Required. 

Where (java servlet) should I put this piece of code in order to create the captcha on html?

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒时光 2024-08-25 12:19:12

要扩展 SimpleCaptcha 并自定义您的验证码,我的理解是您必须创建自己的 HttpServlet (可能扩展 SimpleCaptchaServlet)。为此,我建议下载 源代码并查看SimpleCaptchaServletStickyCaptchaServlet。这就是 SimpleCaptchaServletdoGet() 方法的样子:

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    Captcha captcha = new Captcha.Builder(_width, _height)
        .addText()
        .addBackground(new GradiatedBackgroundProducer())
        .gimp()
        .addNoise()
        .addBorder()
        .build();

    CaptchaServletUtil.writeImage(resp, captcha.getImage());

    req.getSession().setAttribute(NAME, captcha);
}

这应该是不言自明的:创建您自己的 servlet 并将您的自定义 Captcha Builder 代码放入 doGet() 方法。然后,按照安装部分的说明进行操作,但不要使用他们的 servlet 之一,而是声明您的 servlet在 web.xml 中。最后,打包/部署您的应用程序。示例捆绑在源代码发行版的 examples 下。如果您需要有关 Web 应用程序的结构、依赖项和打包的更多指导,请查看它。

To extend SimpleCaptcha and customize your CAPTCHA, my understanding is that you'll have to create your own HttpServlet (maybe extends SimpleCaptchaServlet). To do so, I suggest to download the source code and to look at SimpleCaptchaServlet or StickyCaptchaServlet. This is what the doGet() method of SimpleCaptchaServlet looks like:

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    Captcha captcha = new Captcha.Builder(_width, _height)
        .addText()
        .addBackground(new GradiatedBackgroundProducer())
        .gimp()
        .addNoise()
        .addBorder()
        .build();

    CaptchaServletUtil.writeImage(resp, captcha.getImage());

    req.getSession().setAttribute(NAME, captcha);
}

This should be self-explaining: create your own servlet and put your custom Captcha Builder code in the doGet() method. Then, follow the instructions of the Installing section but, instead of using one of their servlet, declare yours in the web.xml. Finally, package/deploy your application. An example is bundled in the source distribution under examples. Check it out if you need more guidance about the structure, the dependencies and the packaging of your web application.

花海 2024-08-25 12:19:12

嘿,你看过这个页面了吗?
http://simplecaptcha.sourceforge.net/installing.html

这就像直接一样我认为它得到了。该项目为您提供了一些开箱即用的 Capcha servlet。您只需将它们映射到您的 web.xml 文件中。您可以继续操作并创建将调用它们的 jsp。

hey have you had a look at this page yet?
http://simplecaptcha.sourceforge.net/installing.html

this is about as straight forward as it gets I think. This project gives you a few Capcha servlets out of the box. You just have to map them in your web.xml file. You can follow along and create the jsp that will call them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文