第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

中文驗(yàn)證碼圖片亂碼

如果生成的含有中文驗(yàn)證碼的圖片亂碼需要按以下方式修改嗎?還是只要添加幾行代碼修改一下就行?

  1. 確認(rèn)%JavaHome%/jre/lib/fonts目錄下存在zysong.ttf,如果不存在,可以將windows下的C:\WINDOWS\Fonts\simsun.ttc復(fù)制到此目錄,然后改名為zysong.ttf。
    2.在%JavaHome%/jre/lib/fonts目錄下執(zhí)行"ttmkfdir -o fonts.dir"命令,重新生成fonts.dir文件,如沒有此命令,請執(zhí)行:sudo apt-get install ttmkfdir。
    3.確認(rèn)/usr/share/fonts/zh_CN/TrueType目錄存在,如果不存在則mkdir創(chuàng)建
    4.確認(rèn)/usr/share/fonts/zh_CN/TrueType目錄下存在zysong.ttf
    5.在%JavaHome%/jre/lib目錄下,執(zhí)行 cp fontconfig.RedHat.3.properties.src fontconfig.properties
    6.重新啟動tomcat

    http://img1.sycdn.imooc.com//56af48df0001967b05120097.jpg

    其實(shí)圖片上應(yīng)為“網(wǎng)驗(yàn)”二字,但是亂碼只看到了“網(wǎng)”字

    這部分源代碼(下載此課程的源代碼):

  2. package com.imooc.kaptcha;


  3. import java.util.Random;


  4. public class ChineseText extends Configurable implements TextProducer {


  • public String getText() {

  • int length = getConfig().getTextProducerCharLength();

  • //char[] charS = getConfig().getTextProducerCharString();

  • String[] s = new String[]{"慕","課","網(wǎng)","教","程","驗(yàn)","證","碼","實(shí)","例"};


  • Random rand = new Random();

  • StringBuffer sb = new StringBuffer();

  • for(int i = 0; i < length; i++){

  • int ind = rand.nextInt(s.length);

  • sb.append(s[ind]);

  • }

  • return sb.toString();

  • }

  1. /**

  2. * 中文實(shí)例

  3. * @return

  4. */

  5. public String getText1() {

  6. int length = getConfig().getTextProducerCharLength();

  7. String finalWord = "", firstWord = "";

  8. int tempInt = 0;

  9. String[] array = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",

  10. "a", "b", "c", "d", "e", "f" };


  11. Random rand = new Random();


  12. for (int i = 0; i < length; i++) {

  13. switch (rand.nextInt(array.length)) {

  14. case 1:

  15. tempInt = rand.nextInt(26) + 65;

  16. firstWord = String.valueOf((char) tempInt);

  17. break;

  18. case 2:

  19. int r1,

  20. r2,

  21. r3,

  22. r4;

  23. String strH,

  24. strL;// high&low

  25. r1 = rand.nextInt(3) + 11; // 前閉后開[11,14)

  26. if (r1 == 13) {

  27. r2 = rand.nextInt(7);

  28. } else {

  29. r2 = rand.nextInt(16);

  30. }


  31. r3 = rand.nextInt(6) + 10;

  32. if (r3 == 10) {

  33. r4 = rand.nextInt(15) + 1;

  34. } else if (r3 == 15) {

  35. r4 = rand.nextInt(15);

  36. } else {

  37. r4 = rand.nextInt(16);

  38. }


  39. strH = array[r1] + array[r2];

  40. strL = array[r3] + array[r4];


  41. byte[] bytes = new byte[2];

  42. bytes[0] = (byte) (Integer.parseInt(strH, 16));

  43. bytes[1] = (byte) (Integer.parseInt(strL, 16));


  44. firstWord = new String(bytes);

  45. break;

  46. default:

  47. tempInt = rand.nextInt(10) + 48;

  48. firstWord = String.valueOf((char) tempInt);

  49. break;

  50. }

  51. finalWord += firstWord;

  52. }

  53. return finalWord;

  54. }

  55. }

正在回答

舉報(bào)

0/150
提交
取消
Java實(shí)現(xiàn)驗(yàn)證碼制作
  • 參與學(xué)習(xí)       59932    人
  • 解答問題       132    個(gè)

本教程就會帶大家學(xué)習(xí)使用java實(shí)現(xiàn)各種驗(yàn)證碼的方法

進(jìn)入課程

中文驗(yàn)證碼圖片亂碼

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號