好吧,页面加载了一个损坏的图像,“查看源代码”选项显示了这个:
<img id="imageCaptcha" src="/myproject/jcaptcha/jpeg/imageCaptcha?id=1374498423" height="40px" width="40px" />
<br> <br>
<input type="text" name="captchaResponse" value="" id="captchaResponse" />
<br> <br>
名称“imageCaptcha”名称在Config.groovy配置
jcaptchas {
imageCaptcha = new GenericManageableCaptchaService(
new GenericCaptchaEngine(
new GimpyFactory(
new RandomWordGenerator(
"abcdefghijklmnopqrstuvwxyz1234567890"
),
new ComposedWordToImage(
new RandomFontGenerator(
20, // min font size
30, // max font size
[new Font("Arial", 0, 10)] as Font[]
),
new GradientBackgroundGenerator(
140, // width
35, // height
new SingleColorGenerator(new Color(0, 60, 0)),
new SingleColorGenerator(new Color(20, 20, 20))
),
new NonLinearTextPaster(
6, // minimal length of text
6, // maximal length of text
new Color(0, 255, 0)
)
)
)
),
180, // minGuarantedStorageDelayInSeconds
180000 // maxCaptchaStoreSize
)
// Uncomment this to enable the sound captcha, you must install FreeTTS for it to work though.
/* sound = new DefaultManageableSoundCaptchaService()*/
}
我配置的标签是:
<jcaptcha:jpeg name="imageCaptcha" height="40px" width="40px"/>
<br> <br>
<g:textField name="captchaResponse" value="" />
<br> <br>
我的控制器页面有:
def jcaptchaService
def index = { }
def processTheForm() {
//Captcha
if (jcaptchaService.validateResponse("imageCaptcha", session.id, params.captchaResponse)) {
//"Text matches" : "Text doesn't match"
System.out.println("captcha!!!");
}
...
因为我还在学习Grails,所以我不明白发生了什么。我是否需要在示例中添加其他内容?感谢。