一段下载功能的代码

系统 1493 0
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 " );
    }
 

一段下载功能的代码


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论