|
<%@page contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.lang.*" %>
<%
// 檢查用戶權限:
// 
String userid = (String) request.getParameter("userid");
System.out.println("userid======"+userid);
String sortid = (String) request.getParameter("sortid");
System.out.println("sortid======"+sortid);
String workspaceid = (String) request.getParameter("workspaceid");
System.out.println("workspaceid======"+workspaceid);
String id = (String) request.getParameter("id");
System.out.println("id======"+id);
String name = (String) request.getParameter("name");
System.out.println("name======"+name);

name=response.encodeURL(new String(name.getBytes(),"GBK"));
System.out.println("name======"+name);
String path = "d:/" + request.getContextPath()+"//" + userid + "//" + workspaceid + "//" + sortid + "//" + id + name ;
//消除輸出流錯誤的代碼 out.clear(); out = pageContext.pushBody();
//File file = new File("d:\\1.txt");
File file = new File(path);
try
 {
name=response.encodeURL(new String(name.getBytes(),"iso-8859-1"));
response.reset();
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=" + name);
ServletOutputStream output = response.getOutputStream();
FileInputStream inStream = new FileInputStream(file);
//循環取出流中的數據
byte[] b = new byte[1024];
int len;
 while((len=inStream.read(b , 0 , b.length)) >0) {
output.write(b,0,len);
}
output.close();
inStream.close();
 } catch(Exception e) {}
%>
|