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(buf, 0, iRead);
15: } else
16: break;
17: }
18: fIS.close();
19: servletOut.flush();
20: servletOut.close();
21: }
22: return null;
假设该Action的操作文件名为showImg.do,则在JSP页面中的实现代码为