页面:
<img src="${ctx}/img/readImg?prizeid=图片名字" />
后台:
只需要传入图片名称即可,
//prizeid 要下载的图片名字
public void readImg(String prizeid) {
FileInputStream fis= null;OutputStream out=null;
try {
out = response.getOutputStream();
//ResultStatic.path+prizeid+".jpg" 图片绝对地址
fis = new FileInputStream(new File(ResultStatic.path+prizeid+".jpg"));byte[] buffer = new byte[1024*8];
//读取文件流
int len = 0;
while ((len = fis.read(buffer)) != -1){
out.write(buffer,0,len);
}
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(out != null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}