zoukankan      html  css  js  c++  java
  • Serlvet Response 输出1x1 图片

    
    
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class Test
     */
    @WebServlet("/Test")
    public class Test extends HttpServlet {
    	private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public Test() {
            super();
            // TODO Auto-generated constructor stub
        }
        private static final String PIXEL_B64  = "R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
        //private static final byte[] PIXEL_BYTES = Base64.decode(PIXEL_B64.getBytes());
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		 
    
    		byte[]    buf = new sun.misc.BASE64Decoder().decodeBuffer(PIXEL_B64);
    
    		try {
    			java.lang.Thread.sleep((long)2000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		// TODO Auto-generated method stub
    		response.setContentType("image/gif");
    		response.getOutputStream().write(buf);
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    	}
    
    }
    
    
  • 相关阅读:
    Tensorflow-卷积神经网络CNN
    Tensorflow-tensorboard展示网络结构
    机器学习十讲-第二讲回归
    Tensorflow-各种优化器总结与比较
    Tensorflow-交叉熵&过拟合
    机器学习十讲-第一讲
    Tensorflow-线性回归与手写数字分类
    Tensorflow-基础使用
    Python-Flask搭建Web项目
    mybatis-plus之逻辑删除&自动填充&乐观锁
  • 原文地址:https://www.cnblogs.com/cpsing/p/3915546.html
Copyright © 2011-2022 走看看