jsp访问本地文件

来源:互联网 发布:面向切面编程 编辑:程序博客网 时间:2024/06/05 18:46

web项目中,jsp访问本地磁盘文件2012-08-22 16:42

以流的方式输出:
1.showPic.jsp
  <img align="top" src="picCreate.jsp?ppath=/image/v.jpg"  id="imgg"/>

2.picCreate.jsp
<%@page import="java.io.*"%>
<%
  try{
  String ppath = request.getParameter("ppath");
  String file = "F:/" + ppath;
  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();
  }catch(Exception e){}
  %>

0 0
原创粉丝点击