[转] img的src通过请求的方式来显示图片

时间:2025-03-20 21:47:10
  • @RequestMapping("getImg2")  
  • public void getImg2(HttpServletRequest request, HttpServletResponse response)  
  •         throws IOException {  
  •     FileInputStream fis = null;  
  •     OutputStream os = null;  
  •     try {  
  •         fis = new FileInputStream("d:/");  
  •         os = ();  
  •         int count = 0;  
  •         byte[] buffer = new byte[1024 * 8];  
  •         while ((count = (buffer)) != -1) {  
  •             (buffer, 0, count);  
  •             ();  
  •         }  
  •     } catch (Exception e) {  
  •         ();  
  •     } finally {  
  •         try {  
  •             ();  
  •             ();  
  •         } catch (IOException e) {  
  •             ();  
  •         }  
  •     }  
  • }