您的位置:首页 > 其它

页面上显示图片 以流的方式获取

2014-03-03 18:19 218 查看
//type的值可以是image/jpeg image/gif image/png image/bmp 根据图片的格式来定

response.setContentType(type + ";charset=utf-8");

//img是要显示的文件名

String fileName = new String((img).getBytes("GBK"), "ISO-8859-1");

response.setHeader("Content-Disposition", "attachment;filename="

+ fileName);

response.addHeader("Pragma", "no-cache");

response.addHeader("Cache-Control", "no-cache");

//path是服务器所在主机的存放图片的路径

InputStream in = new FileInputStream(new File(path));

int num = 0;

byte[] buf = new byte[1024];

while ((num = in.read(buf)) != -1) {

response.getOutputStream().write(buf, 0, num);

}

response.getOutputStream().flush();

return null;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐