通过引用另一个写入IO流的jsp得以实现:
<img src="Photo.jsp?photo=${c.photo}" width="100" height="100"/
${c.photo}是我的文件名 如flower.jpg
Photo.jsp中写:
<%@ page import="java.io.*" %>
<%
String photo=request.getParameter("photo");
//你文件所在的绝对路径 注意“\\\\”与“/”
String file = "E:/upload/"+photo;
FileInputStream in = new FileInputStream(new File(file));
OutputStream o = response.getOutputStream();
int l = 0;
byte[] buffer = new byte[4096];
while((l = in.read(buffer)) != -1){
o.write(buffer,0,l);
}
o.flush();
in.close();
o.close();
out.clear();
out = pageContext.pushBody();
%>