民宿專案知識 伺服器路徑與檔案的儲存

2022-05-22 05:48:09 字數 756 閱讀 9759

1,檔案的硬碟儲存路徑(檔案存放在伺服器的根目錄,而不是專案,防止伺服器重啟,資源丟失)

得到專案的名字:如,renli

string path1 = request.getcontextpath();

path1=path1.substring(1);

string path2 = request.getsession().getservletcontext().getrealpath("");

string path2 = request.getsession().getservletcontext().getrealpath("").replace(path1, "");

path2=path2.substring(0, path2.length()-1)+"resources";

2,資源的網路訪問路徑:http://localhost:8080/resources

3,擷取檔名:

string prefix = filename.substring(filename.lastindexof(".") + 1);

uuid uuid = uuid.randomuuid();

filename = uuid + "." + prefix;

4,判斷file為空

file.isempty()

win伺服器與Linux伺服器的路徑相容

在寫 的時候,在本地上明明是好的,但是傳到linux伺服器上之後各種報錯,還都是報檔案路徑錯誤,明明自己的路徑是沒問題的,但是就是報這個錯,這時候就要考慮相容問題了。眾所周知,在windows下路徑分隔符是 當然 在部分系統上也是可以正常執行的 在linux上路徑的分隔符是 這就導致了乙個問題,比如...

常用的伺服器路徑

一 專案的物理路徑 string fullfilepath request.getsession getservletcontext getrealpath 二 file.separator的使用 因為在windows作業系統和linux作業系統下,檔案的分隔符是不一樣的,所以直接使用file.se...

檔案伺服器與web伺服器分離的的

要實現的功能是 在一台網路伺服器上啟動了tomcat伺服器,執行乙個很大的 使用者可以登入 然後上傳檔案和 等,由於擔心硬碟空間的問題,希望使用者上傳的檔案等,能夠上傳並儲存到另一台機器上,同時使用者登入後又可以實時檢視到自己之前上傳的檔案,並且需要保證檔案和 安全性。在iteye 上看到有人說 把...