本文实例讲述了jsp中获取当前目录的实现方法,分享给大家供大家参考。具体实现方法如下:
1、利用system.getproperty()函数获取当前路径:
# 对于getcanonicalpath()函数,“."就表示当前的文件夹,而”..“则表示当前文件夹的上一级文件夹
# 对于getabsolutepath()函数,则不管”.”、“..”,返回当前的路径加上你在new file()时设定的路径
# 至于getpath()函数,得到的只是你在new file()时设定的路径
比如当前的路径为 c:test :
获取 java 程序当前的工作目录
① 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程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
[杭电多校2020]第一场 1004 Distinct Sub-palindromes
Swift -- 将本地生成的UIImage进行持久化保存(存到文件中fileManager.createFile)
网友评论