java serviclt 验证码

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        BufferedImage bufferedImage = new BufferedImage( 80, 20, BufferedImage.TYPE_INT_RGB );
        Graphics g = bufferedImage.getGraphics();
        g.setColor( Color.blue );
        g.fillRect( 0,0,80,20 );
        g.setColor( Color.black );
        g.setFont(new Font( null,Font.BOLD,20 ));
        g.drawString( "asdas",0,20 );
        resp.setContentType( "image/jpeg" );
        resp.setDateHeader( "expires",-1 );
        resp.setHeader( "Cacge-Control","no-Cache" );
        ImageIO.write(bufferedImage,"jpg",resp.getOutputStream());


    }

java serviclt 验证码

 

上一篇:JAVA基础--重新整理(1)后版


下一篇:java生成简单验证图片工具类