jps页面实现文件下载

 

<%@page import="java.io.*"%>

<%

String fileNameFlag = request.getParameter("fileName");

System.out.println("--fileName---"+fileNameFlag);

 

 

    String filePath = "E:/workspace1/b2b/ui/gecs/AppAccount/2012-10-19/";

   

    String path = filePath + fileNameFlag;

    System.out.println("--filePath---"+filePath);

   

path=new String(path.getBytes("iso-8859-1"));

File file = new File(path);

InputStream in = new FileInputStream(file);

OutputStream os = response.getOutputStream();

response.addHeader("Content-Disposition", "attachment;filename="

+ new String(file.getName().getBytes("gbk"),"iso-8859-1"));

response.addHeader("Content-Length", file.length() + "");

//        response.setCharacterEncoding("iso-8859-1");

response.setContentType("application/octet-stream");

int data = 0;

while ((data = in.read()) != -1) {

os.write(data);

}

os.close();

in.close(); 

%>

你可能感兴趣的:(文件下载)