0
  • 最佳答案

    你这是现象,缺少代码,log有的话就给吧。编辑问题,补充一下吧。

    1153952789488054272  评论     打赏       拉大锯
    • CodeWwang  回复 @拉大锯
      代码提交了,目前还在看
      CodeWwang 2020-06-27 04:55:23   回复 1276328181644685312
    • CodeWwang  回复 @拉大锯
      下午睡了一觉猛然发现复制粘贴的时候 少写了2个break
      CodeWwang 2020-06-27 10:36:12   回复 1276328181644685312
    • 拉大锯  回复 @CodeWwang
      哈哈,那你太累了,哈哈。有空多睡觉。
      拉大锯 2020-06-27 11:17:10   回复 1153952789488054272
  • 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());
    
            }
        }
    }
    
    1276328181644685312  评论     打赏       CodeWwang
    • CodeWwang  回复 @CodeWwang
      这是代码,因为还没看到后面,就自己简单整合了一下,发现除了前俩个正常,后面3个Session取的值都是三个字的中文,和前端展示不一致
      CodeWwang 2020-06-27 04:55:03   回复 1276328181644685312
    • 拉大锯  回复 @CodeWwang
      老哥,你好歹打Log呀,把这些 captcha3.text()呀。如果实在不行,你就用英文和字母呗,这是框架的问题。或者你可以换一个框架。
      拉大锯 2020-06-27 05:03:17   回复 1153952789488054272
    • CodeWwang  回复 @拉大锯
      好的,感谢
      CodeWwang 2020-06-27 05:48:25   回复 1276328181644685312
相关问题
kaa110 · 圣达菲
2025-09-14 06:47 1 2
下雨天像 · 找工作 / 面试题
2025-08-10 17:31 20 16
资质平平 · Android
2025-02-20 09:14 115 100
尖沙咀-段坤 · 项目
2025-01-06 23:39 35 2
雅澤yaduo · 领券联盟
2025-01-03 20:39 78 50
呆瓜小董 · webview
2024-11-30 18:02 96 20
阿肥 · 鸿蒙next
2024-10-25 18:07 46 100
尖沙咀-段坤 · 安卓
2024-09-11 11:03 46 2
YanLQ · AOSP
2024-08-10 11:57 54 100
断点 · vue
2024-08-08 10:05 105 30