img标签读取本地图片

时间:2025-03-25 08:45:11
// 给img赋图片
	<img id = "preview"src="./static/images/">
	$("#preview").attr("src",img_url+headerurl);  
	//图片地址
	var img_url ="http://localhost:8080/leaseWeb/?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 = ();
		// 得到文件大小
		byte data[] = new byte[i];
		(data);
		// 读数据
		("image/*");
		// 设置返回的文件类型
		OutputStream outStream = ();
		// 得到向客户端输出二进制数据的对象
		(data);
		// 输出数据
		();
		();
		();
	}