图片显示(无缓存)

 

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

 

 

@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">

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(java,Web,无缓存,图片显示)