img标签读取本地图片

xiaoxiao2021-02-28  94

// 给img赋图片 <img id = "preview"src="./static/images/img.jpg"> $("#preview").attr("src",img_url+headerurl); //图片地址 var img_url ="http://localhost:8080/leaseWeb/showImg.shtml?headerUrl="; @RequestMapping(value = "showImg") public void ShowImg(HttpServletRequest request, HttpServletResponse response, @RequestParam("headerUrl") String url) throws IOException { FileInputStream fileIs = null; try { fileIs = new FileInputStream(url); } catch (Exception e) { return; } int i = fileIs.available(); // 得到文件大小 byte data[] = new byte[i]; fileIs.read(data); // 读数据 response.setContentType("image/*"); // 设置返回的文件类型 OutputStream outStream = response.getOutputStream(); // 得到向客户端输出二进制数据的对象 outStream.write(data); // 输出数据 outStream.flush(); outStream.close(); fileIs.close(); }
转载请注明原文地址: https://www.6miu.com/read-55859.html

最新回复(0)