img的src地址是一个请求的方式来显示图片
2015-11-24 17:09
429 查看
1.jsp
<img alt="test" src="getImg2.do">
2.controller
@RequestMapping("getImg2")
public void getImg2(HttpServletRequest request, HttpServletResponse response)
throws IOException {
FileInputStream fis = null;
OutputStream os = null;
try {
fis = new FileInputStream("d:/log.png");
os = response.getOutputStream();
int count = 0;
byte[] buffer = new byte[1024 * 8];
while ((count = fis.read(buffer)) != -1) {
os.write(buffer, 0, count);
os.flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fis.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
<img alt="test" src="getImg2.do">
2.controller
@RequestMapping("getImg2")
public void getImg2(HttpServletRequest request, HttpServletResponse response)
throws IOException {
FileInputStream fis = null;
OutputStream os = null;
try {
fis = new FileInputStream("d:/log.png");
os = response.getOutputStream();
int count = 0;
byte[] buffer = new byte[1024 * 8];
while ((count = fis.read(buffer)) != -1) {
os.write(buffer, 0, count);
os.flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fis.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
相关文章推荐
- java_网格组布局
- MAC上IDEA 导入项目出现\65279错误的解决办法
- 私人编程最佳实践
- 一个界面使用scrollView和UITableView,共用一个scrollViewDidScroll 方法
- js获取与java交互
- oracle 参数游标和存储过程的结合使用
- sql: sybase 和 oracle 比较
- C语言实现链表之双向链表(三)创建链表
- OVER(PARTITION BY)函数用法
- 数组的基本操作(二)
- 最小生成树
- Swift中的反射
- 函数指针的使用
- java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
- 从Hadoop到Spark
- 50个提高PHP程序运行效率的方法
- Android Studio打包、获取SHA1和MD5值
- 前端见微知著番外篇:Bitbucket进行代码管控
- struts2 using kindeditor upload pictures (including jmagic compressed images)
- 谈谈测试用例