- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Jsp生成页面验证码的方法
Jsp生成页面验证码的方法
生成随机验证码图片的Jsp页面
image.jsp生成随机验证码图片的Jsp页面
代码如下:
复制代码 代码如下:
%@ page contentType=image/jpeg import=java.awt.*,
java.awt.image.*,java.util.*,javax.imageio.* %
%!
Color getRandColor(int fc,int bc)
{
Random random = new Random();
if(fc255) fc=255;
if(bc255) 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);
}
%
%
out.clear();//这句针对resin服务器,如果是tomacat可以不要这句
response.setHeader(Pragma,No-cache);
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();
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font(Times New Roman,Font.PLAIN,18));
g.setColor(getRandColor(160,200));
for (int i=0;i155;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);
}
String sRand=;
for (int i=0;i4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
// 将认证码存入SESSION
session.setAttribute(rand,sRand);
g.dispose();
ImageIO.write(image, JPEG, response.getOutputStream());
%
logic.jsp登陆页面,在这里提供输入验证码然后提交并验证
代码如下:
复制代码 代码如下:
%@ page contentType=text/html;charset=gbk %
%@ page language=java import=java.sql.* errorPage= %
html
head
meta http-equiv=Content-Type content=text/html; charset=gb2312
title用户登录/title
script language=javascript
function loadimage(){
document.getElementById(randImage).src = image.jsp?+Math.random();
}
/script
/head
body
table width=256 border=0 cellpadding=0 cellspacing=0
!--DWLayoutTable--
form action=validate.jsp method=post name=loginForm
tr
td width=118 height=2
您可能关注的文档
- Impact of impregnation chemical on the bending strength of solid and laminated wood materials.pdf
- Impact of interface roughness on perpendicular transport and domain formation in superlatti.pdf
- Impact of Optical Modes on the Pairing Potential in Bilayer Cuprates.pdf
- Impact of largex resummation on parton distribution functions.pdf
- Impact of Receive Antenna Selection on Scheduling for Orthogonal Space Division Multiplexing.pdf
- Impact of Selection for Residual Feed Intake on Forage Intake by Beef.pdf
- Impact of Reference Distance for Motion Compensation Prediction on Video Quality.pdf
- Impact of squark pair decay modes on search for supersymmetric neutral Higgs bosons.pdf
- Impact of the tip radius on the lateral resolution in piezoresponse force microscopy.pdf
- Impact of Transportation Costs on Facility Location Decisions.pdf
文档评论(0)