



下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、public class VerifyCode private String sRand = ; protected String sNode =AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz; protected String sFonts = new StringTimes New Roman,Comic Sans MS,華文行楷, MS Mincho,Gungsuh,Sylfaen,Arial, Franklin Gothic Medium,Century; public Color getRandColor(int fc, in
2、t bc) / 給定范圍獲得隨機(jī)顏色 Random random = new Random(); if (fc 255) fc = 255; if (bc 255) bc = 255; int r = fc + random.nextInt(bc - fc); int g = fc + random.nextInt(bc - fc); int b = fc + random.nextInt(bc - fc); return new Color(r, g, b); public BufferedImage creatImage() / 在內(nèi)存中創(chuàng)建圖象 int width = 80, heigh
3、t = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); / 獲取圖形上下文 /Graphics g = image.getGraphics(); Graphics2D g = image.createGraphics(); AffineTransform tx =new AffineTransform(); /調(diào)整字體變形,可以產(chǎn)生效果,但不理想 /tx.scale(1.2, 0.9); g.transform(tx); / 生成隨機(jī)類 Random random =
4、 new Random(); / 設(shè)定背景色 g.setColor(getRandColor(200, 250); g.fillRect(0, 0, width, height); / 設(shè)定字體 g.setFont(new Font(this.getCurrentFonts(), Font.PLAIN, 18); / 畫邊框 / g.setColor(new Color(); / g.drawRect(0,0,width-1,height-1); / 隨機(jī)產(chǎn)生155條干擾線,使圖象中的認(rèn)證碼不易被其它程序探測(cè)到 g.setColor(getRandColor(160, 200); for (i
5、nt i = 0; i 155; i+) int x = random.nextInt(width); int y = random.nextInt(height); int xl = random.nextInt(12); int yl = random.nextInt(12); g.drawLine(x, y, x + xl, y + yl); / 取隨機(jī)產(chǎn)生的認(rèn)證碼(4位數(shù)字) for (int i = 0; i =50) ii=50; else rand = String.valueOf(random.nextInt(10); sRand += rand; / 將認(rèn)證碼顯示到圖象中 g
6、.setColor(new Color(20 + random.nextInt(110), 20 + random .nextInt(110), 20 + random.nextInt(110); /調(diào)用函數(shù)出來(lái)的顏色相同,可能是因?yàn)榉N子太接近,所以只能直接生成 g.drawString(rand, 13 * i + 6, 16); / 圖象生效 g.dispose(); return image; public String getSRand() return sRand; public void setSRand(String rand) sRand = rand; /* * 隨機(jī)產(chǎn)生是數(shù)
7、字還是字符 */ public boolean getRandomBoolResult() int i =(int) (Math.round(Math.random() * 4) ); if(i%2=0) return true; return false; 二使用方法public class VerifyCodeAction extends Action Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletRes
8、ponse response) throws Excep tion VerifyCode verify = new VerifyCode(); /獲得一個(gè)實(shí)例 response.setHeader(Pragma, No-cache); /設(shè)置頭屬性 response.setHeader(Cache-Control, no-cache); response.setDateHeader(Expires, 0); BufferedImage buffImage = verify.creatImage(); /得到驗(yàn)證碼圖片 HttpSession session = request.getSession(true); session.setAttribute
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 山東工商學(xué)院《水力學(xué)及橋涵水文》2023-2024學(xué)年第二學(xué)期期末試卷
- 寧夏職業(yè)技術(shù)學(xué)院《能源與動(dòng)力專業(yè)導(dǎo)論》2023-2024學(xué)年第二學(xué)期期末試卷
- 南通職業(yè)大學(xué)《交通設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 四川科技職業(yè)學(xué)院《高級(jí)管理學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 黑龍江工商學(xué)院《化工安全風(fēng)險(xiǎn)評(píng)估與防范》2023-2024學(xué)年第二學(xué)期期末試卷
- 咸陽(yáng)職業(yè)技術(shù)學(xué)院《妨害社會(huì)管理秩序罪研究》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東南華工商職業(yè)學(xué)院《計(jì)算機(jī)組成與體系結(jié)構(gòu)實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 寧夏葡萄酒與防沙治沙職業(yè)技術(shù)學(xué)院《環(huán)境科學(xué)前沿》2023-2024學(xué)年第二學(xué)期期末試卷
- 黔南民族醫(yī)學(xué)高等??茖W(xué)?!夺樋椃b設(shè)計(jì)與工藝》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西金融職業(yè)學(xué)院《高級(jí)物流學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- T-SCSTA001-2025《四川省好住房評(píng)價(jià)標(biāo)準(zhǔn)》
- 西紅門鎮(zhèn)生活垃圾轉(zhuǎn)運(yùn)站及環(huán)衛(wèi)停車場(chǎng)工程報(bào)告表
- 2025年信息系統(tǒng)監(jiān)理師考試題(附答案)
- 農(nóng)村留守兒童教育支持體系構(gòu)建研究
- 車場(chǎng)管理考試試題及答案
- 福建省三明市2025年普通高中高三畢業(yè)班五月質(zhì)量檢測(cè)物理(三明四檢)
- 人教版(2024)七年級(jí)下冊(cè)Unit 3 Keep fit 素養(yǎng)檢測(cè)(含解析)
- 2025年四川省成都市成華區(qū)中考二診英語(yǔ)試題(含筆試答案無(wú)聽力音頻及原文)
- 綏化綏化市2025年度“市委書記進(jìn)校園”事業(yè)單位引才287人筆試歷年參考題庫(kù)附帶答案詳解
- 中國(guó)數(shù)據(jù)中心產(chǎn)業(yè)發(fā)展白皮書023年
- 醫(yī)院檢驗(yàn)科實(shí)驗(yàn)室生物安全程序文件SOP
評(píng)論
0/150
提交評(píng)論