在shopxx看到JCaptcha验证码的应用,感觉效果很好,就模仿着应用到一个步项目上,结果在验证的时候一直不成功,代码如下: public String userLogin() throws Exception {

String captchaID = getRequest().getSession().getId();
System.out.println("captchaID==="+captchaID);
String challengeResponse = StringUtils.upperCase(getRequest().getParameter(JCaptchaEngine.CAPTCHA_INPUT_NAME));
System.out.println("challengeResponse is =="+challengeResponse);boolean b = false;  b = captchaService.validateResponseForID(captchaID, challengeResponse);
  
System.out.println("b is .... "+b);if(b == true){
System.out.println("captchaID == challengeResponse");
}else{
System.out.println("challengeResponse != captchaID");
}
System.out.println("没过验证码");
if (captchaService.validateResponseForID(captchaID, challengeResponse) != true) {
System.out.println("正在验证中");
loginMessage = "验证码输入错误!";
return SUCCESS;
}
System.out.println("过验证码");
User u = this.userService.getUserByusername(this.getUsername());
if (u != null) {
if (!(DigestUtils.md5Hex(this.getPassword())).equals(u
.getPassword())) {
loginMessage = "密码不正确";
return SUCCESS;
}
// 必须实现SessionAware接口才能生效
session.put(Constant.USER_SESSION_KEY, u);
loginMessage = "";
return SUCCESS;
} else {
loginMessage = "用户名不正确";
return SUCCESS;
}
}Console打印如下(先输入一次正确的验证码,后来又输入一次错误的):captchaID===86C7CC75394980E6CE55CA29476497E8
challengeResponse is ==PSYK
b is .... true
captchaID == challengeResponse
没过验证码
===========================================(下面是错误的,就这两行)
captchaID===86C7CC75394980E6CE55CA29476497E8
challengeResponse is ==FFF
请大家帮忙看下,因为我是第一次用JCaptcha,配置方面也不知道有没有遗漏,请知道的大哥说下使用JCaptcha需要在哪几个文件配置(我已经在applicationContext.xml和web.xml配置)。 或者说下我发出的那个action方法有没有不对的地方,谢谢了。。