jsp中数字验证码
来源:互联网 发布:淘宝直接访问的危害 编辑:程序博客网 时间:2024/05/20 10:55
数字验证码是一种最常用的验证字符码形式,以下为数字实现的JSP源码:
Num.jsp<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int cc,int bb)
{
Random random = new Random();
if(fc>255) cc=255;
if(bc>255) bb=255;
int r=cc+random.nextInt(bb-cc);
int g=cc+random.nextInt(bb-cc);
int b=cc+random.nextInt(bb-cc);
returnnew Color(r,g,b);
} //获取随机颜色
%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
int width=80; //定义验证码图片的长度
int height=30; //定义验证码图片的宽度
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 i_x = random.nextInt(width);
int i_y = random.nextInt(height);
int i_xl = random.nextInt(12);
int i_yl = random.nextInt(12);
g.drawLine(i_x,i_y,i_x+i_xl,i_y+i_yl);
}
//用线条画背景
String s_Rand="";
for (int i=0;i<4;i++)
{
String rand=String.valueOf(random.nextInt(10));
s_Rand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
//产生4位随机码
session.setAttribute("rand",s_Rand);
//将验证码存入Session中
g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());
//输出验证图片
out.clear();
out = pageContext.pushBody();
%>
- jsp中数字验证码
- JSP数字验证码
- JSP数字 验证码
- jsp中随机数字验证码的实现方法
- JSP生成数字验证码
- JSP 数字验证码模板
- jsp验证码(数字+字母)
- JSP彩色验证码 字母+数字
- JSP生成数字验证码教程
- jsp验证数字
- JSP验证码大全之数字验证码(源码)
- JSP验证码大全之数字验证码(源码)
- 利用JSP在Web页面中显示随机数字验证码图片
- 利用JSP在Web页面中显示随机数字验证码图片
- 利用JSP在Web页面中显示随机数字验证码图片
- JSP验证码系列(数字验证码、英文与数字混合验证码、中文验证码、表达式验证码)
- JSP中生成验证码
- JSP中使用验证码
- 打印正三角形
- [问题解决]Visio“搜索形状"不能用
- 需要序列化的类中没有写serialVersionUID的解决办法
- 虚拟机VMware导致Visual Studio 2005打不开的解决方法
- struts2中struts-default.xml配置
- jsp中数字验证码
- 哪些编程语言是最流行的
- QT 读写配置文件
- 使用socat做端口映射
- 树言树语:优酷=油枯?盈利增长遭质疑
- WinCE5.0 之SIP
- 2010-12-10
- wireshark研究,阶段性完结
- WindowsFormsParkingWindow 问题