Servlet返回图片

public class PictureServlet extends HttpServlet { private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String imagePath = "C://1.gif"; FileInputStream fis = new FileInputStream(imagePath); int size =fis.available(); //得到文件大小 byte data[]=new byte[size]; fis.read(data); //读数据 fis.close(); response.setContentType("image/gif"); //设置返回的文件类型 OutputStream os = response.getOutputStream(); os.write(data); os.flush(); os.close(); } }

你可能感兴趣的:(c,String,servlet,OS,Class,byte)