图片上传到服务器位置 ,显示 不使用路径 + 图片名 ,而是使用 下载流 显示
@RequestMapping(value = "/downloadfile")
public void downloadfile(HttpServletRequest req, HttpServletResponse rsp) {
try {
// <meta http-equiv="Pragma" content="no-cache"/>
rsp.setHeader("Cache-Control", "no-cache");
rsp.setHeader("Pragma", "no-cache");
rsp.setDateHeader("Expires", 0);
String filename = req.getParameter("filename");
File file = new File(sysConfigService.getTmpdir() + File.separatorChar + filename);
ServletOutputStream out = rsp.getOutputStream();
FileInputStream in = new FileInputStream(file);
byte b[] = new byte[1024];
int len = 0;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
out.flush();
out.close();
} catch (FileNotFoundException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.error("", e);
}
}
<img class="icon" src="/xxx/upload/downloadfile?filename=default-appicon.png">
捐助开发者
在兴趣的驱动下,写一个
免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。

谢谢您的赞助,我会做的更好!