圖例如下
成都創(chuàng)新互聯(lián)是一家成都網(wǎng)站設計、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設,提供網(wǎng)頁設計,網(wǎng)站設計,網(wǎng)站制作,建網(wǎng)站,按需定制,網(wǎng)站開發(fā)公司,自2013年起是互聯(lián)行業(yè)建設者,服務者。以提升客戶品牌價值為核心業(yè)務,全程參與項目的網(wǎng)站策劃設計制作,前端開發(fā),后臺程序制作以及后期項目運營并提出專業(yè)建議和思路。具體操作如下:
新建一個servlet,代碼如下:標記一個WebServlet,
1 @WebServlet(urlPatterns = {"/checkCode"}) //驗證碼Servlet
繪制驗證碼圖片的核心代碼:
int width = 100; int height = 50; //創(chuàng)建圖片對象 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); //美化圖片 Graphics g = image.getGraphics(); //1:填充背景 g.setColor(Color.pink); g.fillRect(0, 0, width, height); //畫邊框 g.setColor(Color.blue); g.drawRect(0, 0, width - 1, height - 1); //生成一個驗證碼字符串 String strCheckCode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Random random = new Random(); StrCheckCode = ""; for (int i = 1; i <= 4; i++) { int index = random.nextInt(strCheckCode.length()); char ch = strCheckCode.charAt(index); StrCheckCode += ch;//拼接驗證碼 g.drawString(ch + "", width / 5 * i, height / 2); } //畫干擾線 for (int i = 0; i < 5; i++) { int x1 = random.nextInt(width); int x2 = random.nextInt(width); int y1 = random.nextInt(height); int y2 = random.nextInt(height); g.drawLine(x1, x2, y1, y2); } //輸出,顯示出來 ImageIO.write(image, "jpg", resp.getOutputStream()); }
本文標題:JavaWeb制作登錄驗證碼實現(xiàn)代碼解析-創(chuàng)新互聯(lián)
文章路徑:http://aaarwkj.com/article44/icgee.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、商城網(wǎng)站、外貿(mào)網(wǎng)站建設、做網(wǎng)站、企業(yè)網(wǎng)站制作、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容