濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > 用jsp頁面生成隨機(jī)的驗(yàn)證數(shù)字碼示例

用jsp頁面生成隨機(jī)的驗(yàn)證數(shù)字碼示例

熱門標(biāo)簽:湖北地圖標(biāo)注公司 智能電話機(jī)器人銷售話術(shù) 汝南縣地圖標(biāo)注app 地圖標(biāo)注專業(yè)和非專業(yè) 福建電銷貓機(jī)器人收費(fèi) 山東ai外呼電銷機(jī)器人好用嗎 外呼直播語音系統(tǒng) 四川正規(guī)外呼系統(tǒng)軟件 甘肅銷售電銷機(jī)器人公司
checkNum.jsp
復(fù)制代碼 代碼如下:

%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,javax.imageio.*"%>

%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

%!
Color getRandColor(int fc,int 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);
}
%>
%
response.setHeader("Pragma","No-cache");//設(shè)置頁面不緩沖
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
int width=60,height=20;
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();//獲取圖像上下文
Random random = new Random();//生成隨機(jī)對(duì)象
g.setColor(getRandColor(200,250));
g.fillRect(0,0,width,height);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));//設(shè)置字體
for(int i=0;i155;i++)
{
int x=random.nextInt(width);
int y=random.nextInt(height);
int x1 = random.nextInt(12);
int y1 = random.nextInt(12);
g.drawLine(x,y,x+x1,y+y1);
}
//隨機(jī)產(chǎn)生驗(yàn)證碼
String sRand = "";
for(int i=0;i4;i++)
{
String rand = String.valueOf(random.nextInt(10));
sRand+=rand;
//將驗(yàn)證碼顯示到圖像中
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
//設(shè)置顯示隨機(jī)數(shù)的顏色
g.drawString(rand,13*i+6,16);
}
//將驗(yàn)證碼存放到session中
session.setAttribute("rand",sRand);
//圖像生效
g.dispose();
//輸出圖像到頁面
ImageIO.write(image,"JPEG",response.getOutputStream());
out.clear();
out = pageContext.pushBody();

%>

可以在登錄login.jsp下直接通過: 這種格式調(diào)用;
驗(yàn)證碼:input class="imgbutton" name="checknum" type="text" size="15" id ="checknum" maxlength="4"/>
img src="checknum.jsp" alt="Change" border="1" onclick="changeCheckNum()"/>br/>
input type="submit" name="submit" value="login"/>
您可能感興趣的文章:
  • JSP實(shí)現(xiàn)百萬富翁猜數(shù)字游戲

標(biāo)簽:白銀 黔東 吳忠 梅州 肇慶 臨沂 南充 昌都

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《用jsp頁面生成隨機(jī)的驗(yàn)證數(shù)字碼示例》,本文關(guān)鍵詞  用,jsp,頁面,生成,隨機(jī),的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《用jsp頁面生成隨機(jī)的驗(yàn)證數(shù)字碼示例》相關(guān)的同類信息!
  • 本頁收集關(guān)于用jsp頁面生成隨機(jī)的驗(yàn)證數(shù)字碼示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    巴南区| 金湖县| 鞍山市| 大连市| 开封县| 庐江县| 交城县| 汝州市| 巴彦县| 兰西县| 安陆市| 河东区| 同心县| 安乡县| 鄂尔多斯市| 独山县| 融水| 伊宁市| 石首市| 赤峰市| 通江县| 北宁市| 永州市| 扶余县| 龙井市| 抚松县| 阳城县| 米林县| 新昌县| 娱乐| 寿阳县| 循化| 贵南县| 上栗县| 盐亭县| 九寨沟县| 菏泽市| 普洱| 镇雄县| 中牟县| 囊谦县|