一段下载功能的代码
2007-06-26 17:03
465 查看
public ActionForward download(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception ...{
this.initActionAttributes(request);
//System.out.println(uploadForm.getFile().getFileName()+"--size is --"+uploadForm.getFile().getFileSize());
String tables=new String(request.getParameter("TABLE_NAME").getBytes("ISO8859_1"));
String table=new String(request.getParameter("TABLE").getBytes("ISO8859_1"));
String con=new String(request.getParameter("SQL_COND").getBytes("ISO8859_1"));
String col=new String(request.getParameter("TITLE_CODE").getBytes("ISO8859_1"));
String colName=new String(request.getParameter("TITLE_NAME").getBytes("ISO8859_1"));
String rowNum=new String(request.getParameter("ROW_NUM").getBytes("ISO8859_1"));
String[] columnName = colName.split(",");
StringBuffer sb=new StringBuffer();
sb.append("select ").append(col).append(" from ").append(tables).append(" where ").append(con).append(" order by (cust.BUSY_IN_CALL_DURATION + cust.IDLE_IN_CALL_DURATION) desc fetch first "+rowNum+" rows only");
StringBuffer updateSql=new StringBuffer();
updateSql.append("update ").append(table).append(" set DOWNLOAD_MARK=1,DOWNLOAD_TIME=current Date where comp_product_no in(select cust.comp_product_no from DMCF_cust_ms cust").append(" where ").append(con).append(" order by (cust.BUSY_IN_CALL_DURATION + cust.IDLE_IN_CALL_DURATION) desc fetch first "+rowNum+" rows only)");
String fileName = "CustInfo" +
new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()) + ".csv";
PrintWriter pw = null;
Sqlca m_Sql = null;
// 保存到客户机上
response.setContentType("application/octet-stream; charset=gbk");
response.setHeader("Content-disposition", "attachment; filename="" + fileName + """);
PrintWriter out1 = null;
try ...{
pw = new PrintWriter(new FileOutputStream(fileName));
out1 = response.getWriter();
//标题vector
Vector titleVector = new Vector();
for (int i = 0; i < columnName.length; i++) ...{
titleVector.add(columnName[i]);
}
for (int j = 0; j < titleVector.size(); j++) ...{
out1.print(new String(String.valueOf(titleVector.elementAt(j)).getBytes("gbk")));
if (j == titleVector.size() - 1)
out1.println();
else
out1.print(",");
out1.flush();
}
m_Sql = new Sqlca(new ConnectionEx(Const.DATASOURCE));
m_Sql.execute(sb.toString());
String tmpStr;
while (m_Sql.next()) ...{
for (int j = 1; j <= titleVector.size(); j++) ...{
tmpStr = "" + m_Sql.getString(j);
out1.write(new String(tmpStr.getBytes("gbk")));
if (j == titleVector.size())
out1.println();
else
out1.print(",");
}
out1.flush();
}
m_Sql.execute(updateSql.toString());
m_Sql.commit();
} catch (Exception exception) ...{
m_Sql.rollback();
if(m_Sql != null)m_Sql.closeAll();
exception.printStackTrace();
} finally ...{
if(m_Sql != null)m_Sql.closeAll();
}
return mapping.findForward("initAction");
}
相关文章推荐
- 我想寻求一段上传下载代码(功能多点)。
- asp.net网站下载功能页面代码
- 我写的一段JS实现TABLE统计功能的代码(未兼容昨天那段代码的JS功能)
- Java实现FTP文件的上传和下载功能的实例代码
- 文件下载功能代码示例
- 站点中,实现: 在线签名 功能 (示例代码下载)
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- 站点中,实现: 在线签名 功能 (示例代码下载)
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载续][重点推荐控件]
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- Asp.net 2.0 C#实现压缩/解压功能 (示例代码下载)
- AjaxPro.NET实现TextBox智能获取服务端数据功能(Asp.net 2.0)(示例代码下载)
- [导入]jquery+.net实现类似开心网图像缩放截取功能(附代码下载)
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载续][重点推荐控件]
- apk安装法之二----一段Android实现应用下载并自动安装apk包的代码
- 4000 MD5加密 加密功能更好的一段代码
- FormValidate 表单验证功能代码更新并提供下载
- Asp.net下载功能的解决方案代码
- [导入]一段不太好的代码:IE主页不是本站地址就不充许访问或下载