美文网首页
jsp引用本地文件

jsp引用本地文件

作者: 矫矫矫 | 来源:发表于2016-07-05 01:00 被阅读0次

通过引用另一个写入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();

%>

相关文章

网友评论

      本文标题:jsp引用本地文件

      本文链接:https://www.haomeiwen.com/subject/uprhjttx.html