java簡單檔案上傳

來源:互聯網
上載者:User

/*
  * 對錶單上傳的檔案進行改名
  */
   private String getNewFilename(String s){
         int i = s.indexOf(".");
         String s1 = s.substring(i+1,s.length());
         java.util.Date today = new java.util.Date();
         String str ="";
         //SimpleDateFormat他在java.text包下面,作用是把一個data對象轉換成我們想要的字串
         SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
         str = formatter.format(today);
         return str+"."+s1;
      } 
  

/* ******************** 檔案上傳 *************************** */  
  
  FormFile file = ef.getFile();
  String Savefilepath = "" ;
  String Savefilename = "" ;
  
      if (!( file.getFileName()).equals(""))
         {
          try {
            InputStream stream = file.getInputStream();//把檔案讀入
            Savefilepath = request.getRealPath("/upload");//將檔案存放在當前系統路徑的哪個檔案夾下                                   
           
            Savefilename = getNewFilename(file.getFileName());
            Savefilepath = Savefilepath + "\\" + Savefilename;
           
            //將檔案名稱存入資料庫
            empl.setRemark(Savefilename);
           
            OutputStream bos = new FileOutputStream(Savefilepath);//建立一個上傳檔案的輸出資料流                     
           
            int bytesRead = 0;
            byte[] buffer = new byte[10*1024];
            while ( (bytesRead = stream.read(buffer, 0, 10240)) != -1) {
              bos.write(buffer, 0, bytesRead);//將檔案寫入伺服器的硬碟上
           }
            bos.close();
            stream.close();
         }catch(Exception e){
           e.printStackTrace();
         }
         }
  
/* ******************** 檔案上傳 ***************************  */ 

 

 <td><IMG width="100" height="100" src="photo/<%=e.getRemark()%>"> </td>

String content = ds.toGBK(ds.toString((String)request.getParameter("content")));

<object classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 width=450 height=400><param name=showstatusbar value=1><param name=filename value='../video/upload/<%=sp%>'><embed src='/news/upload/1.wmv'></embed></object>

 

jdbc:oracle:thin:@192.168.0.13:1521:dbstudy

oracle.jdbc.driver.OracleDriver
  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.