Rising Sun

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  148 随笔 :: 0 文章 :: 22 评论 :: 0 Trackbacks
String cl=new String(req.getParameter("checkboxvalue").getBytes("iso8859-1"),"gb2312");

excel

 Connection connection = DbConnectionManager.getConnection();
        try{
          
         
            PreparedStatement prst = connection.prepareStatement(sql);
            ResultSet rs = prst.executeQuery();
            if(rs.next()){
             //if(rs == null){rs.close();
                Blob blob = rs.getBlob("bb");
             
                byte[] ab = blob.getBytes(1, (int)blob.length());
                //URLEncoder.encode(rname, "utf-8");
                //new String("文件名.xls".getBytes("GBK"),"ISO8859_1")
                //response.setHeader("Charset","gb2312");
                //application/msexcel-comma
                String fs = new String(rname.getBytes("GBK"),"ISO8859_1");
                
                response.reset();
                response.setLocale(java.util.Locale.CHINA);
                response.setContentType("application/vnd.ms-excel");
                request.setCharacterEncoding("GBK");
              
              
                String s = "attachment; filename="+fs;
                response.setHeader("Content-Disposition", s);
                ServletOutputStream op = response.getOutputStream();
                op.write(ab);
                op.flush();
                op.close();
            }
         }catch(SQLException e){
        log.info(e.toString()+"sql:"+sql);
     }
         catch(NullPointerException ex){
          System.out.print("数据为空");
         }
        
         finally{
         try{
         connection.close();
       }catch(Exception e){
        System.out.print("ddd");
       }
posted on 2006-07-18 16:26 brock 阅读(189) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: