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;"/> &nbsp;&nbsp;&nbsp;
             <input type="reset" value="重置"  style="height: 35px; width:90px ;color:#FFFFFF;font-size: 16px;border-radius: 15%;background-color: #6495ED;"/>
        </td>
    </tr>
  </table> 

本文标签: 验证码页面