chrome无法显示JSP生成的验证码

yanchuangdear 2016-04-07 02:34:32
<img class="col-xs-9" name="randImage" id="randImage" src="image.jsp" onclick="loadimage()">
在IE/firfox中都可以显示
而且在chrome中右键验证码打开图片是能看到的,为什么在原页面上看不到呢
<%@ page language="java" import="java.util.*" contentType="text/html; charset=gbk"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/buttons.css" />
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap-datetimepicker.css" />-->
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap-datetimepicker.min.css" />-->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-2.2.2.min.js"></script>
<!--<script src="js/bootstrap-datetimepicker.min.js"></script>-->
<title></title>
<script>
function loadimage(){
document.getElementById("randImage").src = "image.jsp?"+Math.random();
}
</script>
</head>
<body>
<header style="text-align: center;">
<h1>欢迎</h1>
</header>
<form class="form-horizontal log-or-sign col-xs-12 col-sm-6 col-md-4 col-lg-3" method="post" action="<%=request.getContextPath()%>/Login">
<fieldset>
<div id="legend" class="">
<legend class="">用户登陆</legend>
</div>
<div class="control-group">
<label class="col-xs-4 control-label" for="uname">用户名</label>
<div class="col-xs-8">
<input type="text" placeholder="用户名" class="form-control" name="username" required="" id="uname">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="col-xs-4 control-label" for="pwd">密码</label>
<div class="col-xs-8 controls">
<input type="password" placeholder="密码" class="form-control" name="password" required="" id="pwd">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="col-xs-4 control-label" for="select">用户身份</label>
<div class="col-xs-8 controls">
<select class="form-control" id="select">
<option value="1">员工</option>
<option value="2">管理员</option>
</select>
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="col-xs-4 control-label" for="rand">验证码</label>
<div class="col-xs-8 controls">
<input type="text" placeholder="验证码" class="form-control" name="rand" required="" id="rand">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="col-xs-4 control-label" for="randImage"></label>
<div class="col-xs-8 controls" >
<img class="col-xs-9" name="randImage" id="randImage" src="image.jsp" onclick="loadimage()">
<p class="help-block"></p>
</div>

</div>
<h1> </h1>
<!--<label for="aa">日期:</label><input id="aa" type="date" value="2014-01-13"/>
<input type="text" value="2012-05-15 21:05" id="datetimepicker">
<script>$('#datetimepicker').datetimepicker({format: 'yyyy-mm-dd hh:ii'});</script> -->
<div class="control-group">
<div class="col-xs-6">
<input type="submit" name="submit" class="button button-glow button-border button-rounded button-primary" value="确定"></input>
</div>
<div class="col-xs-6">
<input type="reset" name="reset" class="button button-glow button-border button-rounded button-primary" value="重置"></input>
</div>
</div>
</fieldset>
</form>
</body>
</html>


<%@ 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);
}
%>
<%

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.setAttribute("rand",sRand);
g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());
%>
...全文
223 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
key800700 2016-04-11
  • 打赏
  • 举报
回复
up up up up 遇到一样的问题,同寻求方法。
howsun_zh 2016-04-07
  • 打赏
  • 举报
回复
写java又写html,哪家公司啊?这么虐待程序员。 貌似栅格写乱了。form 里不要用bootstrap的栅格,另起<div>写。
奄灬苟且偷生 2016-04-07
  • 打赏
  • 举报
回复
来涨涨见识 我还以为原页面是一个浏览器那,误导我

81,116

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧