jsp中獲取當前目錄的方法
來源:易賢網 閱讀:1145 次 日期:2016-07-01 08:59:00
溫馨提示:易賢網小編為您整理了“jsp中獲取當前目錄的方法”,方便廣大網友查閱!

本文實例講述了jsp中獲取當前目錄的實現方法,分享給大家供大家參考。具體實現方法如下:

1、利用system.getproperty()函數獲取當前路徑:

代碼如下:

system.out.println(system.getproperty(user.dir));//user.dir指定了當前的路徑

2、使用file提供的函數獲取當前路徑:

代碼如下:

file directory = new file();//設定為當前文件夾

try{

system.out.println(directory.getcanonicalpath());//獲取標準的路徑

system.out.println(directory.getabsolutepath());//獲取絕對路徑

}catch(exceptin e){}

file.getcanonicalpath()和file.getabsolutepath()大約只是對于new file(.)和new file(..)兩種路徑有所區別。

# 對于getcanonicalpath()函數,“.就表示當前的文件夾,而”..“則表示當前文件夾的上一級文件夾

# 對于getabsolutepath()函數,則不管”.”、“..”,返回當前的路徑加上你在new file()時設定的路徑

# 至于getpath()函數,得到的只是你在new file()時設定的路徑

比如當前的路徑為 c:test :

代碼如下:

file directory = new file(abc);

directory.getcanonicalpath(); //得到的是c:testabc

directory.getabsolutepath(); //得到的是c:testabc

direcotry.getpath(); //得到的是abc

file directory = new file(.);

directory.getcanonicalpath(); //得到的是c:test

directory.getabsolutepath(); //得到的是c:test.

direcotry.getpath(); //得到的是.

file directory = new file(..);

directory.getcanonicalpath(); //得到的是c:

directory.getabsolutepath(); //得到的是c:test..

direcotry.getpath(); //得到的是..

獲取 java 程序當前的工作目錄

代碼如下:

file file = new file(t.tmp);

string fullpath = file.getabsolutepath();

① request.getrealpath:

方法:request.getrealpath(/)

得到的路徑:c:program filesapache software foundationtomcat 5.5webappsstrutstest

方法:request.getrealpath(.)

得到的路徑:c:program filesapache software foundationtomcat 5.5webappsstrutstest.

方法:request.getrealpath()

得到的路徑:c:program filesapache software foundationtomcat 5.5webappsstrutstest

方法:request.getrealpath(web.xml)

得到的路徑:c:program filesapache software foundationtomcat 5.5webappsstrutstestweb.xml

② request.getparameter();

actionform.getmyfile();

方法:string filepath = request.getparameter(myfile);

得到的路徑:d:vss安裝目錄users.txt

方法:string filepath = actionform.getmyfile();

得到的路徑:d:vss安裝目錄users.txt

希望本文所述對大家的jsp程序設計有所幫助。

更多信息請查看網頁制作
易賢網手機網站地址:jsp中獲取當前目錄的方法
由于各方面情況的不斷調整與變化,易賢網提供的所有考試信息和咨詢回復僅供參考,敬請考生以權威部門公布的正式信息和咨詢為準!

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
云南網警備案專用圖標
聯系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網
云南網警報警專用圖標
未满十八18勿进黄网站免费看