一段下载功能的代码
来源:互联网 发布:甘肃网络广播电视台 编辑:程序博客网 时间:2024/05/23 01:17
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");
}
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");
}
- 一段下载功能的代码
- 一段下载的代码
- 一段折叠代码,带记忆功能的
- 记事本打印功能的一段代码
- 一段下载魔兽世界历史音频的代码
- php实现文件下载的一段代码
- php实现文件下载的一段代码
- 一段显示下载进度条的下载文件代码
- 一段显示下载进度条的下载文件代码
- 一段来源于《精通Qt编程》的文件传输功能的代码
- Jsp下载文件 一段代码
- Hibernate中的一段批量插入功能的代码
- MD5加密 加密功能更好的一段代码
- J2SSH Maverick 一段连接sftp服务器,上传,下载的代码:
- 递归下载网页内容的一段简单代码
- 一段不可思议的代码
- 一段写晕掉的代码
- 一段好玩的代码
- Write to the event log in a .net project
- ASP.NET性能优化总结
- dataset.HasChanges
- 数据库连接池~~hoho
- 在SAS存储过程使用SMC中定义的逻辑库
- 一段下载功能的代码
- TCP序列号和确认号详解
- red Hat AS4 非图形界面安装oracle 10.2客户端,并访问远程数据库
- EJBCA安装的文档
- 游戏注入CALL
- C#编程命名规则
- Oracel 转义字符
- 好词语和文档的收入
- 随便试试