thebigcrow

BlogJava 首页 联系 聚合 管理
  0 Posts :: 11 Stories :: 0 Comments :: 0 Trackbacks
 
Action类中的方法实现为
 1: File file = new File(ImgPath);//ImgPath是图像文件的路径
 2:
if (file.exists()) { 
 3:
response.reset();
 4:
response.setContentType('image/jpeg');
 5:
response.setContentLength((int) file.length());
 6:
FileInputStream fIS = new FileInputStream(file);
 7:
ServletOutputStream servletOut response.getOutputStream();
 8:
 9:
byte[] buf = new byte[1024];
10:
int iRead 0;
11: while (
true) { 
12:   
iRead fIS.read(buf);
13:   if (
iRead 0) { 
14:   
servletOut.write(buf0iRead);
15:    } else
16:   break;
17:    }
18:   
fIS.close();
19:   
servletOut.flush();
20:   
servletOut.close();
21:  }
22: return 
null;

假设该Action的操作文件名为showImg.do,则在JSP页面中的实现代码为
1: <img src='showImg.do?path=××××' >
转自:http://www.54bk.com/more.asp?name=boy002&id=20979
posted on 2005-11-07 10:36 技术乌鸦 阅读(500) 评论(0)  编辑  收藏 所属分类: STRUTS