Where to place Java Simple Captcha Builder?

I am new to java / java servlet. I need simpleCaptcha for the form using html and javaservlet for 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 to create a captcha in html?

Many thanks.

+5
source share
2 answers

To extend SimpleCaptcha and configure CAPTCHA, I understand that you will need to create your own HttpServlet(possibly extends SimpleCaptchaServlet). To do this, I suggest downloading the source code and looking at SimpleCaptchaServletor StickyCaptchaServlet. This is what the method looks like doGet() SimpleCaptchaServlet:

@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);
}

: Captcha Builder doGet(). Installing, web.xml. , / . examples. , , -.

+8
+2

All Articles