点击这里使用RSS订阅本Blog:
jsp实现彩色验证码 你只用复制粘贴就可以了
转自【http://www.blogjava.net/zcq87642231/archive/2008/02/24/181748.html】
Demo1.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="ISO-8859-1"%>
<%@pageimport="java.awt.*"%>
<%@pageimport="java.awt.image.*"%>
<%@pageimport="javax.imageio.*"%>
<%!
ColorgetRanColor(intfc,intbc)
{
Randomrandom=newRandom();
if(fc>255)fc=255;
if(bc>255)bc=255;
intr=fc+random.nextInt(bc-fc);
intg=fc+random.nextInt(bc-fc);
intb=fc+random.nextInt(bc-fc);
returnnewColor(r,g,b);
}
%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-che");
response.setDateHeader("Expires",0);
intwidth=60;
intheight=20;
BufferedImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphicsg=image.getGraphics();
Randomrandom=newRandom();
g.setColor(getRanColor(200,250));
g.fillRect(0,0,width,height);
g.setFont(newFont("TimesNewRoman",Font.PLAIN,18));
g.setColor(getRanColor(160,200));
for(inti=0;i<155;i++)
{
intx=random.nextInt(width);
inty=random.nextInt(height);
intxl=random.nextInt(12);
intyl=random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
StringsRand="";
for(inti=0;i<4;i++)
{
Stringrand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(newColor(20+random.nextInt(110),40+random.nextInt(110),60+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
session.setAttribute("rand",sRand);
g.dispose();
ImageIO.write(image,"JPEG",response.getOutputStream());
%>
Demo.jsp
<%@pagelanguage="java"pageEncoding="gbk"%>
<%@tagliburi="http://struts.apache.org/tags-bean"prefix="bean"%>
<%@tagliburi="http://struts.apache.org/tags-html"prefix="html"%>
<%@tagliburi="http://struts.apache.org/tags-logic"prefix="logic"%>
<%@tagliburi="http://struts.apache.org/tags-tiles"prefix="tiles"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html:htmllang="true">
<head>
<html:base/>
<title>Demo.jsp</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="Thisismypage">
<!--
<linkrel="stylesheet"type="text/css"href="styles.css">
-->
</head>
<body>
<formaction="Demo2.jsp">
<inputtype="text"name="asd"><imgborder="0"src="Demo1.jsp">
<br>
<inputtype="submit"name="b"value="点击">
</form>
</body>
</html:html>
Demo2.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="ISO-8859-1"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<title>MyJSP'Demo2.jsp'startingpage</title>
</head>
<body>
<%
Stringinput=request.getParameter("asd");
Stringrand=(String)request.getSession().getAttribute("rand");
if(input.equals(rand))
{
}
else
{
%>
<jsp:forwardpage="Demo.jsp"></jsp:forward>
<%
}
%>
asdasd
</body>
</html>
1
分享到:
相关推荐
JSP实现彩色验证码(源码示例)
JSP实现彩色验证码实现具体源代码
JSP彩色验证码的实现JSP彩色验证码的实现JSP彩色验证码的实现JSP彩色验证码的实现
JSP实现彩色验证码源代码
java生成验证码源码包括彩色验证码 包括jsp生成验证码和彩色验证码
jsp实现验证码技术实例 jsp实现验证码技术实例
JSP随机验证码实例源码.rar
jsp彩色验证码.rar jsp彩色验证码.rar
JSP彩色验证码JSP彩色验证码JSP彩色验证码
基于JSP的彩色验证码实现。需要注意的地方是验证码是为了安全才加的,所以把它做成图片的格式让别人难以破解。所以contentType="image/jpeg; charset=utf-8"而不是 contentType="text/html; charset=utf-8
经典JSP生成验证码经典JSP生成验证码经典JSP生成验证码经典JSP生成验证码经典JSP生成验证码经典JSP生成验证码经典JSP生成验证码
在JSP里面实现图片验证代码,用户用户登录或者注册
JSP实现的图片验证码, 验证码JSP实现 .
本源码只要按要求在Eclipse中进行操作,就能实现想要分效果,
JSP中彩色验证码 注册验证码 中文验证码 图片验证码的生成
请按文档要求建立3个jsp页面,一个是image.jsp就是产生验证码的,一个a.jsp就是用来展示验证码的一个表单,一个check.jsp就是用来验证验证码和表单里面用户输入的验证码的值是否一致。 注意:三个jsp文件的路径,a....
jsp图形验证码源码,实现系统自动生成图片验证,输出随机验证码图片流,并返回验证码值,生成指定验证码图像文件。
jsp实现图形验证码
jsp验证码的实例 源码不是文档 直接复制文件即可
JSP生成彩色验证码程序