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());


    }

 

posted @ 2021-02-16 15:19  酷酷的城池  阅读(19)  评论(0编辑  收藏  举报