Running the Example Applications

Example implementations are provided for Grails and J2EE. These are intended to show various ways of using SimpleCaptcha, how to customize it, and what it is capable of.

Grails

This is a simple Grails application used to exercise the Builder. This is the best and easiest way to get a feel for how to generate your own CAPTCHAs: changing up the code which generates the CAPTCHAs is a simple matter of changing Groovy scripts, rather than tinkering with servlets.

There is also an example of how to use SimpleCaptcha with Spring via Grails’ Spring DSL. See grails-app/controllers/SpringController.groovy and grails-app/conf/spring/resources.groovy.

Installing

From source:

  1. Clone the git repo (instructions here).
  2. Go to the examples/grails/ directory
  3. Make sure that the SimpleCaptcha jar file (or a link to it) is in the examples/grails/lib/ directory.
  4. Run grails run-app
  5. Browse to http://localhost:8080/sc.

As a deployable war:

  1. Download the Grails sample app.
  2. Deploy it to your servlet container.

Using

Once installed and running you should see something like this:

There are many examples provided here. The source for all the controllers is available in the examples/Grails/sc/grails-app/controllers directory. For example, here is the code used to generate /sc/chinese/block, taken from ChineseController.groovy:

1     def block = {
2         def captcha = new Captcha.Builder(WIDTH, HEIGHT)
3             .addText(new ChineseTextProducer())
4             .gimp(new BlockGimpyRenderer())
5             .build()
6         CaptchaServletUtil.writeImage(response, captcha.image)
7     }

It should be emphasized that the Grails application is the best place to test out any custom CAPTCHAs of your own.

J2EE

This is a bare-bones J2EE implementation that shows how to generate CAPTCHAs using SimpleCaptcha, how to set up the application, configure web.xml, and so forth. You can either download the .war, or you can build it from source using the build-war Ant task in build.xml. This will put the sc.war file into the dist/ directory.

Installation

This is container dependent, but for most containers simply copying the .war file to the appropriate location and restarting the server will automatically deploy it. All necessary .jar files are included with the war.

For Tomcat simply copy the sc.war file to your webapps directory and restart. If you are using Tomcat’s default settings you will then browse to http://localhost:8080/sc.

You should see something like the following:


To keep the examples simple this is all done using straight JSPs, with the exception of the servlets used to generate the CAPTCHAs. In your implementation you will, of course, want to use your MVC framework of choice. View the source of the JSPs to get a feel for how the flow works.

Addendum: JavaFX

If you look in the source you’ll see that there is a JavaFX directory. At one point I had a working JavaFX implentation of SimpleCaptcha, but after I upgraded the code to Java 6 it stopped working. Something – either NetBeans or JavaFX itself – requires Java 1.5, at least on OS X.

This was a briefly-successful experiment. If interest is expressed in getting a JavaFX implementation I will look into resurrecting it.

Home

Download SimpleCaptcha

Installing

Customizing

Example Applications

Source

Javadocs