JSP验证码刷新无效问题解决
在form表单中,如下
[html]
<form name="infof">
<font color="red">姓名:</font> <input name="name" type="text"></input><br>
<font color="red">密码:</font> <input name="password" type="password"></input><br>
验证码:<input name="validate" type="text">
<img name="vali" border=0 src="validate.jsp" onclick="refresh()"/>
<a href="JavaScript:refresh()">看不清,换一张</a>
<br>
<input type="button" onclick="login()" value="登录"> <input
type="reset">
</form>
在验证码图片中,调用的是validate.jsp,用于生成验证码图片。这个jsp中的内容如下:
[html]
<body>
<%
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
BufferedImage image = new BufferedImage(75, 30,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.gray);
g.fillRect(0, 0, 75, 30);
String randStr = String.valueOf(new Random().nextInt(8999) + 1000);
session.setAttribute("randStr", randStr);
g.setColor(Color.black);
g.setFont(new Font("", Font.PLAIN, 20));
g.drawString(randStr, 10, 20);
for (int i = 1; i <= 120; i++) {
int x = new Random().nextInt(75);
int y = new Random().nextInt(30);
g.setColor(Color.blue);
g.drawOval(x, y, 1, 1);
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>