JSP验证码源码大全将分别用几个篇幅内容来介绍在JSP中几种验证码实现源码以及使用
、JSP中产生数字验证码源码
数字验证码是种最常用验证码形式以下为数字实现JSP源码:
Num.jsp
<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %> prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Color getRandColor( cc, bb)
{
Random random = Random;
(fc>255) cc=255;
(bc>255) bb=255;
r=cc+random.nextInt(bb-cc);
g=cc+random.nextInt(bb-cc);
b=cc+random.nextInt(bb-cc);
Color(r,g,b);
} //获取随机颜色
%>
<%
response.Header("Pragma","No-cache");
response.Header("Cache-Control","no-cache");
response.DateHeader("Expires", 0);
width=80; //定义验证码图片长度
height=30; //定义验证码图片宽度
BufferedImage image = BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics;
Random random = Random;
g.Color(getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.Font( Font("Times New Roman",Font.PLAIN,18));
g.Color(getRandColor(160,200));
for ( i=0;i<155;i)
{
i_x = random.nextInt(width);
i_y = random.nextInt(height);
i_xl = random.nextInt(12);
i_yl = random.nextInt(12);
g.drawLine(i_x,i_y,i_x+i_xl,i_y+i_yl);
}
String s_Rand="";
for ( i=0;i<4;i)
{
String rand=String.valueOf(random.nextInt(10));
s_Randrand;
g.Color( Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
session.Attribute("rand",s_Rand);
g.dispose;
ImageIO.write(image, "JPEG", response.getOutputStream);
//输出验证图片
out.clear;
out = pageContext.pushBody;
%>
接下来文章将介绍JSP中中文验证码、其他JAVA验证码实现以及对JSP中对验证码和使用有关内容下篇文章将介绍有关JSP中文验证码源码实现
最新评论