日期:2014-05-18  浏览次数:20703 次

关于jsp生成验证码图片的问题
我准备写个jsp生成验证码的例子,在网上找了个:
                            hehe.jsp
<%@   page   contentType= "text/html;charset=GBK "
        import= "java.awt.*,java.awt.image.*,java.util.*,javax.imageio.* "              
            pageEncoding= "GBK "%>
           
<html>
          <body>
         
            <%!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