以下的config文件用来下载zip文件
<action name="DownloadEtmZip" method="downloadZip" class="jp.co.westlaw.cms.web.action.etm.EtmSearch">
<param name="operationId">1601</param>
<result name="zipFile" type="stream">
<param name="contentType">application/x-zip-compressed</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="etmSearch.zip"</param>
<param name="bufferSize">8192</param>
</result>
</action>contentType没问题吧?
是不是我得在后台把要下载的zip文件变成InputStream流?
public InputStream getInputStream() throws Exception {
return new ByteArrayInputStream(zipData.getBytes());
}望高手执教,在线等!!!!
<action name="DownloadEtmZip" method="downloadZip" class="jp.co.westlaw.cms.web.action.etm.EtmSearch">
<param name="operationId">1601</param>
<result name="zipFile" type="stream">
<param name="contentType">application/x-zip-compressed</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="etmSearch.zip"</param>
<param name="bufferSize">8192</param>
</result>
</action>contentType没问题吧?
是不是我得在后台把要下载的zip文件变成InputStream流?
public InputStream getInputStream() throws Exception {
return new ByteArrayInputStream(zipData.getBytes());
}望高手执教,在线等!!!!
楼主【pagliucali】截止到2008-07-03 14:08:36的历史汇总数据(不包括此帖):
发帖的总数量:3 发帖的总分数:80
结贴的总数量:2 结贴的总分数:0
无满意结贴数:2 无满意结贴分:70
未结的帖子数:1 未结的总分数:80
结贴的百分比:66.67 % 结分的百分比:0.00 %
无满意结贴率:100.00% 无满意结分率:---------------------
楼主加油
/**
* 导出数据实体(针对常用任意文件类型)
*
* @return
* @throws IOException
*/
public void DownloadExpDataEntity() throws IOException {
boolean exp = false;
OutputStream os = null;
String filename = selectSXH[0].split(",")[1]; // 列表页面被选中的一个条记录 传过来的
// 该条记录的主键
String s = "application/octet-stream";
os = getResponse().getOutputStream();
getResponse().setContentType(s);
String fileName = URLEncoder.encode(filename, "UTF-8");
// 设置文件下载头
getResponse().addHeader("Content-Disposition", "attachment;filename="
+ fileName);
UploadZhljsjtJDBCService uploadjdbcservice = new UploadZhljsjtJDBCService();
exp = uploadjdbcservice.DownloadExpDataEntity(os, selectSXH[0]);
os.close();
}service 方法
/**
* 导出数据实体
*
* @param jhdm
* 井号代码
* @param sxh
* 顺序号
* @param fileurl
* 保存文件路径
* @param filename
* 保存文件名
* @return exp 导出成功与否标志
*/
public boolean DownloadExpDataEntity(OutputStream os, String sxh) {
// TODO Auto-generated method stub
boolean exp = false;
Connection con = null;
PreparedStatement preStmt = null;
ResultSet rset = null;
InputStream inStream = null;
try {
BaseDao basedao = new BaseDao();
con = basedao.getConnection();
preStmt = con
.prepareStatement("select ZHLJSJST from ZHLJ_ZHLJSJT where SXH=?");
preStmt.setString(1, sxh.split(",")[0]);
rset = preStmt.executeQuery();
rset.next();
rset.getBlob("ZHLJSJST");
oracle.sql.BLOB zhljsjst = (oracle.sql.BLOB) rset.getBlob(1);
// ======= 创建输出文件路径
// 获取输入流对象
inStream = zhljsjst.getBinaryStream();
byte[] buf = new byte[1024 * 10];// 10K 读取缓存
int len;
while ((len = inStream.read(buf)) > 0) {
os.write(buf, 0, len);
}
rset.close();
preStmt.close();
con.close();
exp = true;
inStream.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (rset != null) {
rset.close();
rset = null;
}
if (preStmt != null) {
preStmt.close();
preStmt = null;
}
if (con != null)
con.close();
con = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return exp;
}
这样就可电机下载 IE自动弹出下载链接
指明设置这个 无所谓
文件下载是一个字节流的传递 用这个就可以application/octet-stream
我上面那个是针对任意文件类型
下载几乎不用考虑文件大小
上传控制上传文件的大小 struts2 是在 struts.xml 里面设置这个
<constant name="struts.multipart.maxSize" value="5242880" /> 这个表示上传文件不能大于50M