在网上找了一天了,只找到如下代码
public ActionForward download(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DocForm df = (DocForm) form;
QuotationService qs = this.getQuotationService();
String docName = qs.getDocName(df.getId(), df.getType());
System.out.println("++++++++++++docName:" + docName);
response.setContentType("APPLICATION/OCTET-STREAM");
try {
response.setHeader("Content-Disposition", "attachment; docName=\""
+ new String(docName.getBytes(), "GBK") + "\"");
System.out.println("======="+new String(docName.getBytes(), "GBK"));
qs.writeDoc(response.getOutputStream(), df.getId(), df.getType());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
可我不知道这句qs.writeDoc(response.getOutputStream(), df.getId(), df.getType()); 中writeDoc方法怎么实现,请高手们指教!
另外高手们还有什么好的下载思路,也多多指明一下,小弟会不胜感激的
public ActionForward download(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DocForm df = (DocForm) form;
QuotationService qs = this.getQuotationService();
String docName = qs.getDocName(df.getId(), df.getType());
System.out.println("++++++++++++docName:" + docName);
response.setContentType("APPLICATION/OCTET-STREAM");
try {
response.setHeader("Content-Disposition", "attachment; docName=\""
+ new String(docName.getBytes(), "GBK") + "\"");
System.out.println("======="+new String(docName.getBytes(), "GBK"));
qs.writeDoc(response.getOutputStream(), df.getId(), df.getType());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
可我不知道这句qs.writeDoc(response.getOutputStream(), df.getId(), df.getType()); 中writeDoc方法怎么实现,请高手们指教!
另外高手们还有什么好的下载思路,也多多指明一下,小弟会不胜感激的
java.io.FileInputStream fileInputStream =
new java.io.FileInputStream(filepath + filename); // 写出流信息
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();