`
knight_black_bob
  • 浏览: 824082 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

图片显示(无缓存)

    博客分类:
  • web
阅读更多

 

图片上传到服务器位置 ,显示 不使用路径 + 图片名 ,而是使用 下载流 显示 

 

 

@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捐助),没钱捧个人场,谢谢各位。



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

 

 

 

分享到:
评论
2 楼 knight_black_bob 2015-08-19  
lmcptbtptp 写道
sysConfigService.getTmpdir()  返回的是什么?

我在数据库配置的上传图片的地址……
1 楼 lmcptbtptp 2015-08-19  
sysConfigService.getTmpdir()  返回的是什么?

相关推荐

Global site tag (gtag.js) - Google Analytics