@RequestMapping(value = "/tupian", method = RequestMethod.GET)
public void IoReadImage(HttpServletRequest request, HttpServletResponse response, String imgPath) throws IOException {
ServletOutputStream out = null;
FileInputStream ips = null;
try {
//获取图片存放路径
//String imgPath = "D:\\学习\\linux文件\\shiJuan-1-500\\0ac201615a63409db498477004f34d9f.jpg";
ips = new FileInputStream(new File(imgPath));
response.setContentType("image/png");
out = response.getOutputStream();
//读取文件流
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = ips.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
ips.close();
}
}
这个是根据图片地址返回给页面图片;直接url请求页面显示该图片
img标签显示该图片:
只设置了高
<img id="img1" src="自己的url" alt="" style="height: 750px"></body>