admin管理员组文章数量:1640023
用的是eclipse的JavaEE版本做的
出现的图片
在浏览器中显示不出来
验证的servlet 代码
public VerificationCodeServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("image/jpge");
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control", "No-cache");
response.setDateHeader("Expires", -1);
OutputStream out = response.getOutputStream();
int width=80,height=20;
//定义画布对象 bufferedimage画布
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//返回画布对象
Graphics g = image.getGraphics();
//定义随机数
Random random = new Random();
g.setColor(Color.gray);
//用预设的颜色填充一个矩形 fill填充 fillrect填充矩形
g.fillRect(0, 0, width, height);
String sRand = "";
for(int i=0;i<4;i++){
//生出0-9的随机数
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, 20*i+6, 16);
}
g.dispose();
ImageIO.write(image,"JPGE",response.getOutputStream());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
登录页面代码
<tr>
<td ><font size="+4"><b>Hotel登录</b></font></td>
</tr>
<br>
<tr>
<td ><font size="4px">用户名:</td>
<td >
<input id="userName" type="text" style="width:140px;height:22px;">
</td>
</tr><br>
<tr>
<td ><font color="dodgerblue"><font size="4px">密码:</td>
<td >
<input id="password" type="password" style="width:140px;height:22px;"></td>
</tr> <br>
<tr>
<td ><font color="dodgerblue"><font size="4px">验证码:</td>
<td>
<input type="text" name="verification" style="width:140px;height:22px;"></td>
<td><img alt="" src="VerificationCodeServlet"></td>
</tr><br>
<tr >
<td > <font color="dodgerblue">注册|忘记密码?
</tr> <br>
<tr>
<td >
<input type="submit" value="登 录" style="height: 35px; width:90px ;color:#FFFFFF;font-size: 16px;border-radius: 15%;background-color: #6495ED;"/>
<input type="reset" value="重置" style="height: 35px; width:90px ;color:#FFFFFF;font-size: 16px;border-radius: 15%;background-color: #6495ED;"/>
</td>
</tr>
</table>
版权声明:本文标题:登录页面显示不了验证码 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729306111a1195058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论