我用ofbiz做一个oa,需要用到文件的上传下载,上传我已经做完了,但下载始终没有实现!我用的javaBean是jspsmartupload,下载时如果是word文档或.rar文件,浏览器总会自动打开,显示乱码!而且出现getOutputStream called错误!希望高手能帮我看一下如何实现文件下载!不胜感谢!download.jsp如下:
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.util.*, org.ofbiz.core.service.ModelService,java.sql.* " %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%!
String docName = ""; 需要下载的文件名
int docSize = 0;
Map document = new HashMap();
LinkedList docList = null;
%>
<%
try
{
List b = delegator.findAll("ProcessDoc",UtilMisc.toList("docName"));
docList = new LinkedList(b);
}catch(Exception ex){System.out.println("查找数据库是出错!");}
try
{
if(docList!=null) docSize = docList.size();
if(docSize!=0)
{
document = (Map)docList.get(docSize-1);
docName = (String)document.get("docName");
}
}catch(Exception e){
System.out.println("取值时候出错!");
System.out.println(e.getMessage());
e.printStackTrace();
}
// Initialization
mySmartUpload.initialize(pageContext);
// Download file
mySmartUpload.downloadFile("/upload/"+docName);
%>