图灵验证码中文和GIF 获取验证码时session和验证码字符不一致
我做了一个随机的测试,可以随机显示不同类型验证码,但是遇到 了问题,png和算数可以。gif, 中文 还是GIF中文都显示错误的中文,希望遇到过的兄弟能指点迷津
您的每一个用心回答,都会让这个世界变得更美好一些!
你这是现象,缺少代码,log有的话就给吧。编辑问题,补充一下吧。
public class VerCodeUtil { public static void generateCode(HttpServletRequest request, HttpServletResponse response) throws IOException, FontFormatException { Random random = new Random(); int randomId = random.nextInt(4); switch(randomId){ case 0: ArithmeticCaptcha captcha1 = new ArithmeticCaptcha(130, 48); captcha1.setFont(Captcha.FONT_1); captcha1.setCharType(Captcha.TYPE_NUM_AND_UPPER); captcha1.setLen(2); // 几位数运算,默认是两位 captcha1.getArithmeticString();// 获取运算的公式:3+2=? // 验证码存入session request.getSession().setAttribute("captcha", captcha1.text().toLowerCase()); // 输出图片流 captcha1.out(response.getOutputStream()); break; case 1: SpecCaptcha captcha2 = new SpecCaptcha(130, 48, 4); captcha2.setFont(Captcha.FONT_3); //aptcha2.setFont(new Font("Verdana", Font.PLAIN, 32)); captcha2.setCharType(Captcha.TYPE_NUM_AND_UPPER); // 验证码存入session request.getSession().setAttribute("captcha", captcha2.text().toLowerCase()); // 输出图片流 captcha2.out(response.getOutputStream()); break; case 2: GifCaptcha captcha3 = new GifCaptcha(130, 48,4); // 验证码存入session request.getSession().setAttribute("captcha", captcha3.text()); // 输出图片流 captcha3.out(response.getOutputStream()); case 3: // 中文类型 ChineseCaptcha captcha4 = new ChineseCaptcha(130, 48,3); captcha4.text(); // 获取验证码的字符 // 验证码存入session request.getSession().setAttribute("captcha", captcha4.text()); // 输出图片流 captcha4.out(response.getOutputStream()); case 4: // 中文gif类型 ChineseGifCaptcha captcha5 = new ChineseGifCaptcha(130, 48,3); captcha5.text(); // 获取验证码的字符 // 验证码存入session request.getSession().setAttribute("captcha", captcha5.text()); // 输出图片流 captcha5.out(response.getOutputStream()); } } }
你这是现象,缺少代码,log有的话就给吧。编辑问题,补充一下吧。