jfinal 重写保存验证码
因为jfianl 生成的验证码保存在当前的Web应用中,浏览器中只有键。在验证验证码的时候,是通过读取cookie中的键,然后在服务器中通过键读取到值,然后进行比较的。在集群部署的情况下,将会出现验证码输入正常。而服务器返回错误的问题。这个时候,我们只需要重新实现ICaptchaCache接口,使用Redis 或者其他方式集中保存就好了
1.实现ICaptchaCache接口
import com.jfinal.captcha.Captcha;
import com.jfinal.captcha.ICaptchaCache;
public class RedisICaptchaCache implements ICaptchaCache{
@Override
public void put(Captcha captcha) {
// 保存验证码信息
}
@Override
public Captcha get(String key) {
// 读取验证码
return null;
}
@Override
public void remove(String key) {
// 删除验证码
}
@Override
public void removeAll() {
// 删除所有验证码
}
}
2.在configConstant 方法中配置

实现的详细可以参考Jfinal 中的默认实现,路径是 com.jfinal.captcha.CaptchaCache
本文来自博客园,作者:小朋友有很多问号,转载请注明原文链接:https://www.cnblogs.com/xuhu/p/15800149.html

浙公网安备 33010602011771号