檔案最好是儲存在web-inf下面!
這樣主要是怕使用者傳送乙個jsp頁面,使用者對這個頁面進行訪問(頁面是使用者自己寫的)如果他裡面加上一些關機啊,刪除檔案的**就麻煩了
所以放在這個下面,客戶就訪問不到這個檔案了
檔案的名字配對的問題
有些瀏覽器上傳的是客戶的絕對路徑,這樣就需要對路徑進行分割,**比較簡單
檔案也許會發生亂碼的情況
在servlet那邊加上乙個request.getcharacterencoding("utf-8")就好了,fileupload內部會自動的來呼叫它
進行檔案打散的操作:將檔名轉成hashcode的值,在轉為16進製制的資料,取第一位數為第乙個資料夾,第二數個為第二個資料夾
主要的**:
diskfileitemfactory factory=new diskfileitemfactory();//建立工廠
servletfileupload fileupload=new servletfileupload(factory);//得到工廠的解析器
try
string reservename=uuid.randomuuid().tostring();//得到一些隨機的數
reservename=realname.replace("-", "")+"_"+realname;//處理掉有減號的問題,並且加上真實的名字以下劃線區分
int number=realname.hashcode();//得到檔名稱的hashcode的值
string hastring=integer.tobinarystring(number);//將得到後的hashcode的值轉化為十六進製制數
string filepath=this.getservletcontext().getrealpath("/web-inf/files");//得到當前專案下的真實的路徑
filepath=filepath+"/"+hastring.charat(0)+"/"+hastring.charat(1);//進行字串的拼接
file newfile=new file(filepath);//將路徑儲存到當前的檔案物件中
newfile.mkdirs();//建立資料夾
file destinationfile=new file(newfile,reservename);//將檔名和專案儲存起來
try catch (exception e)
//fileitem fileitem=fileitems.get(0);//得到第乙個fileitem物件的
"屬性的名字為:"+fileitem.getname()+" 值為:"+fileitem.getstring("utf-8"));//得到第乙個屬性的名字和傳入的值
輸出為: 屬性的名字為:null 值為:愛你哦
//fileitem fileitem2=fileitems.get(1);//得到第二個fileitem物件
"檔案的名稱:"+fileitem2.getname()+" 檔案的型別:"+fileitem2.getcontenttype());//獲取檔案的名稱,以及獲取檔案的型別
輸出為: 檔案的名稱:愛你哦 檔案的型別:image/jpeg
//file file=new file("d:");//建立該檔案的物件
//try catch (exception e) //輸出到該檔案物件中
} catch (fileuploadexception e) //
SIFT的一些細節問題(三)
其實以下問題不一定要歸結到sift的內容當中來,因為這是關於特徵點匹配方面的,只是由於我是在看sift的時候接觸到這些,並且也只是有一點粗淺的了解,將一些基礎的總結性的知識儲備在這裡吧。不能算問題,只能是知識點。2 kd 樹建立。簡單地說,kd 樹是將n維特徵向量按照一定的規則在某一維中劃一條 直線...
Oracle中的一些細節問題
例 按部門統計各部門員工人數,要求顯示部門號,部門名,人數,並按照降序排列 select d.deptno,count e.empno d.dname from emp e,dept d where e.deptno d.deptno group by d.deptno,d.dname order ...
C 的一些細節
1.c 中,將負數賦值給unsigned是完全合法的。例如,將 1賦值給unsigned char,那麼結果是255.2.c 中,double的精度和計算速度都要超過float,long double則需要承擔額外的執行代價。3.std ou t hi d endl 等價於std out hi 4....