导航:首页 > 编程语言 > java生成验证码jsp

java生成验证码jsp

发布时间:2021-02-27 03:22:58

java web 写了个verificationCode.jsp验证码页面,然后调用<img src="verificationCode.jsp"/>

我觉得还是路径问题,你看看放入一个跟verificationCode.jsp路径一样的图片进入能不能显示出来

❷ java中 验证码代码只能写在Servlet和jsp中吗

不是说只能放在servlet和jsp中,只能说是数据必须经过这2个地方。。。至于怎么经过,怎么调用,根据个人喜好和系统性能确定。

❸ 用java随机生成四位验证码,只求编程代码

不知道你问的是不是生成这种图片验证码?
如果只要一个随机四位数 那这行代码就够了(new Random().nextInt(9000) + 1000;),
如果是生成页面图片验证码就是下面的了:
//设定 响应模式
resp.setContentType("image/jpeg");

// 生成令牌环数据;
Integer token = new Random().nextInt(9000) + 1000;

// 保存令牌环数据到session中
req.getSession().setAttribute(IMAGE_TOKEN_NAME, token);

// 生成令牌环图片
ServletOutputStream out = resp.getOutputStream();
BufferedImage img = new BufferedImage(60, 20,
BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setColor(Color.YELLOW);
g.fillRect(0, 0, img.getWidth(), img.getHeight());
g.setColor(Color.BLUE);
g.setFont(new Font("", Font.BOLD, 18));
g.drawString(String.valueOf(token), 10, 16);
ImageIO.write(img, "jpg", out);
out.close();

❹ 在java页面上,用jsp,怎样写一个验证码

//验证码生成页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import = " java.awt.*,java.awt.image.*,javax.imageio.* " %>
<%@ page import = " java.io.OutputStream " %>
<%!
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);
}
%>
<%
try {
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);
OutputStream os = response.getOutputStream();
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.setAttribute("vcode" ,sRand);
g.dispose();

ImageIO.write(image, "jpg" ,os);
os.flush();
os.close();
os = null ;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch (IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
} %>

//验证码使用页面
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function refresh(){
co=document.getElementById("code");
co.src="vcode.jsp?vcode="+Math.random();
}
</script>
</head>

<body>
用户名:<input type="text" name="name"><br/>
<img id="code" title="验证码" src="vcode.jsp"><a href="javascript:refresh();">换一张</a>
</body>
</html>

❺ 在我的java Web项目中为什么我的jsp的验证码不能显示啊其他项目可以显示就是我的这一个项目不能显示。

如果其他可以,这个不行,你可以试着重启你的服务器,清除浏览器缓存再打开试试..

❻ 在Javaweb中,我用一个jsp页面生成一个验证码图片并用session保存图片上的数字,然后又

为什么要放在session.太浪费资源。放在request里面。每次请求的时候后台生成一个新的数字就request.setAttribult,页面getAtrribult就可以了。你网络下用法就懂了

❼ java中如何在同一个jsp页面中判断图片验证码与输入的是否一致

这个问题很简单的。我想你动态产生的验证码一定是一个单独的页面然后再把这个页面导入到你的输入信息的页面的。你打开你的动态生成验证码的页面。在里面你一定可以找到一个session.setAttribute(""); 这个方法是把你验证码的值保存在session里面。根据你的意思在用js弹出来验证. 首先你在页面中加一小脚本<% Stirng vcode= (String)session.getAttribute("验证码Key") %>然后在你的提交按钮中加一个onClick事件... 请输入验证码:<input type="text" id="txtvcode" name="txtvcode" /> <input type="button" name="text" id="text" value="提交" onClick="checkVcode('<%= vcode%>')" />这样就可以把你动态生成的验证码值传入到js的函数中去了。 <script> function checkVcode(vcode){ var txtvcode= document.getElementById("txtvcode").value; if(vcode==txtvcode){ alert("输入验证码正确"); }else{ alert("输入验证码错误"); } } </script>人在网吧。没工具调试。我想这些代码不会出问题的。

❽ J2EE中JSP页面怎么获取JAVA类里生成的随机验证码

直接 <img src="your image request url" >

❾ java验证码的问题。在验证码jsp中保存到session与响应到登陆页面中的一致。但是登陆页面中

看看是不是缓存的原因,你的获取验证码url是否加了时间戳的标识。

阅读全文

与java生成验证码jsp相关的资料

热点内容
pythonwriteexcel文件 浏览:794
有奶电影 浏览:646
百度移动端排名工具 浏览:938
安卓安装程序不见了 浏览:251
3d9中文精简版找不到文件 浏览:839
手机能关联哪些app 浏览:423
电影播放量排行榜在哪里看 浏览:717
网络销售办公图片素材 浏览:390
ps肉色代码 浏览:258
快穿以肉为主 浏览:376
券商的数据分析工程师怎么样 浏览:31
日本武士恐怖电影 浏览:120
电影电视剧小孩子的恋爱 浏览:383
怎么下载pptv网络电视 浏览:3
邵氏论理电影 浏览:142
ps怎么导成制作文件 浏览:273
文件夹和桌面同步快捷方式 浏览:187
阿里云如何上传压缩文件 浏览:244
李彩谭作品大全 浏览:955

友情链接