img的src地址是一个请求的方式(把图读成流在内存中 )来显示 远程的 图片

时间:2025-03-20 21:48:50
HTML:
<div > <img src= "${ctx}/common/file/getImgs?name=" style="width: 300px; height: 300px;" alt="logo"></div>

Java:
 @RequestMapping("getImgs")
    public void getImg2(HttpServletRequest request, HttpServletResponse response,String name)  throws IOException {
        if(null !=name && !("")){
            FileInputStream fis = null;
            OutputStream os = null;
          
            try {
         //公共服务器目录地址
                fis = new FileInputStream("\\\\W01DFS0185\\LDMS\\training_video_docs\\"+name);
                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) {
                    ();
                }
            }
        }
    }