- 浏览: 857486 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
yukang1:
蚂蚁lovejing 写道我也出现与楼上相同的问题。查了一些资 ...
Spring中实现文件上传 -
史玉凤:
必须用ie浏览器
javascript获取客户端网卡MAC地址和IP地址和计算机名 -
蚂蚁lovejing:
我也出现与楼上相同的问题。查了一些资料,描述的跟楼主的博文差不 ...
Spring中实现文件上传 -
温柔一刀:
djlijian 写道最近也在研究redis,如何在项目中使用 ...
Redis 常见的性能问题和解决方法 -
djlijian:
最近也在研究redis,如何在项目中使用呢?感觉网上的资料太少 ...
Redis 常见的性能问题和解决方法
login.jsp--------------------登录页面,在这里我是提供输入验证码然后提交进行验证
代码如下:
<!----> <% @ page contentType = " text/html; charset=gb2312 " %>
< 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 = " 22 " valign = " middle " align = " center " >< input type = " text " name = " rand " size = " 15 " ></ td >
< td width = " 138 " valign = " middle " align = " center " >< img alt = " code " name = " randImage " id = " randImage " src = " image.jsp " width = " 60 " height = " 20 " border = " 1 " align = " absmiddle " ></ td >
</ tr >
< tr >
< td height = " 36 " colspan = " 2 " align = " center " valign = " middle " >< a href = " javascript:loadimage(); " >< font class = pt95 > 刷新 </ font ></ a ></ td >
</ tr >
< tr >
< td height = " 36 " colspan = " 2 " align = " center " valign = " middle " >< input type = " submit " name = " login " value = " 提交 " ></ td >
</ tr >
</ form >
</ table >
</ body >
</ html >
< 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 = " 22 " valign = " middle " align = " center " >< input type = " text " name = " rand " size = " 15 " ></ td >
< td width = " 138 " valign = " middle " align = " center " >< img alt = " code " name = " randImage " id = " randImage " src = " image.jsp " width = " 60 " height = " 20 " border = " 1 " align = " absmiddle " ></ td >
</ tr >
< tr >
< td height = " 36 " colspan = " 2 " align = " center " valign = " middle " >< a href = " javascript:loadimage(); " >< font class = pt95 > 刷新 </ font ></ a ></ td >
</ tr >
< tr >
< td height = " 36 " colspan = " 2 " align = " center " valign = " middle " >< input type = " submit " name = " login " value = " 提交 " ></ td >
</ tr >
</ form >
</ table >
</ body >
</ html >
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 (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);
}
%>
<%
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 ;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);
}
String sRand = "" ;
for ( int i = 0 ;i < 4 ;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());
%>
java.awt.image. * ,java.util. * ,javax.imageio. * " %>
< %!
Color getRandColor( int fc, int bc)
{
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);
}
%>
<%
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 ;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);
}
String sRand = "" ;
for ( int i = 0 ;i < 4 ;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());
%>
validate.jsp-------------用来验证输入的验证码是否正确
代码如下:
<% @ page contentType = " text/html; charset=gb2312 " %>
<%
String rand = ( String )session.getAttribute( " rand " );
String input = request.getParameter( " rand " );
if (rand.equals(input)) {
out.print( " <script>alert('验证通过!');</script> " );
} else {
out.print( " <script>alert('请输入正确的验证码!');location.href='login.jsp';</script> " );
}
%>
<%
String rand = ( String )session.getAttribute( " rand " );
String input = request.getParameter( " rand " );
if (rand.equals(input)) {
out.print( " <script>alert('验证通过!');</script> " );
} else {
out.print( " <script>alert('请输入正确的验证码!');location.href='login.jsp';</script> " );
}
%>
发表评论
-
Spring Integration 1.0 发布
2008-11-20 14:34 2085终于迎来了spring integration的第一个fina ... -
When To Use Mock Objects?
2008-06-10 10:18 1574The real object has nondeterm ... -
JACOB发送传真
2008-03-21 19:46 3767JACOB一个JAva-COM中间件.通过这个组件你可以在Ja ... -
IDEA快捷键
2007-04-30 12:16 5546最常用快捷键 1.Ctrl+E,可以显示最近编辑的文件列表 2 ... -
Ant+Tomcat自动部署的小问题
2007-02-14 18:00 8409今天用Ant对dms系统进行Tomcat的自动部署。 通过a ... -
FCKeditor-2.3在线编辑器,可以直接用的(java版)
2007-02-12 12:11 39380初次使用FCKeditor编辑器, 在网上搜索了半天也没有找 ... -
Java是剑客-飘逸;.NET是刀客-霸道
2006-12-26 19:17 4916网上看到的一篇 ... -
常用到的Eclipse快捷键
2006-11-11 12:13 3363Ctrl+s 存盘 Ctrl+/ ... -
java操作Excel、PDF文件
2006-10-09 16:41 36212下面这些是在开发中用到的一些东西,有的代码贴的不是完整的,只是 ... -
通过SCJP考试,说点体会和感受
2006-04-25 18:58 4847我就随便说说哈,不认可的朋友就当没有看见哈! 1、首先声明下 ... -
使用smartupload进行文件的上传下载
2006-06-07 23:30 5268jspSmartUpload是由www.jspsmart.co ... -
log4j的配置文件例子
2006-07-09 04:27 2993log4j的配置文件例子,非常方便的一个开源日志软件,一直用它 ... -
javaBean数据库连接池
2006-07-09 04:35 2674实现简单的数据库连接池: java 代码 / ... -
用java实现浮点数的精确计算
2006-07-13 22:28 2884问题的提出: 如果我们编译运行下面这个程序会看到什么? j ... -
工厂模式
2006-07-13 22:30 5108简单工厂模式 1. 目的 工厂模式就是专门负 ... -
61条面向对象设计的经验原则
2006-07-13 22:51 1822(1)所有数据都应该隐藏在所在的类的内部。 (2)类的使用者必 ... -
追MM与java的32种模式
2006-07-13 22:55 1810创建型模式 1、FACTORY—追MM少不了请吃饭了,麦当 ... -
OO的五大原则
2006-07-14 19:25 4721OO的五大原则是指SRP ... -
JAVA系列之对象的序列化与反序列化
2006-07-17 09:09 177841 简介 对象序列化(Seria ... -
java获取服务器端网卡地址
2006-08-08 19:43 4246java 代码 package com.ctgu ...
相关推荐
HTML实现,有随机生成的验证码+按钮+输入框
java随机生成验证码
随机生成验证码工具类 长度为4位或者6位
Python中PIL模块实现的随机生成验证码图片用于网站登录验证.
Java随机生成验证码图片,适用于web登录验证等。个人觉得很不错~
调用编写的java类随机生成验证码进行用户输入验证码
Android中两种方式随机生成验证码源代码, 可验证是否正确。
验证码工具jar包,随机生成验证码
winform随机生成验证码案例
易语言源码易语言随机生成验证码源码.rar 易语言源码易语言随机生成验证码源码.rar 易语言源码易语言随机生成验证码源码.rar 易语言源码易语言随机生成验证码源码.rar 易语言源码易语言随机生成验证码源码.rar ...
QT实现随机生成验证码
易语言随机生成验证码源码,随机生成验证码,刷新验证码
做好 备份 为以后 唤起 jsp随机生成验证码 记忆
生成动态验证码类 ,使用纯白色填充矩形框,也可以使用干扰码,随机颜色、随机摆放、随机字符串向图像输出 。
随机生成验证码源码(java)
JavaScript实现随机生成验证码及校验 本文实例为大家分享了JavaScript实现随机生成验证码及校验的具体代码,供大家参考,具体内容如下 输入验证码(区分大小写)点击确认,进行校验。出错就弹框提示 点击 看不清...
一款简单又实用的jQuery随机生成验证码插件代码,随机生成字母数字混合验证码图片显示,点击图片更换验证码。
整合了一下验证码的生成,以备不时之需,利用servlet写的eclipse项目
把本页面放入web工程,加入IMAGE,它的imageUrl设成ValidateCode.aspx搞定,可实现随机生成验证码。验证代码:protected void btnLogin_Click(object sender, EventArgs e) { if (Session[ValidateCode....