jsp的各种路径获取

来源:互联网 发布:财会软件 编辑:程序博客网 时间:2024/05/22 05:21

1、jsp中如何获得url路径  request.getHeader("referer");


2、根目录所对应的绝对路径:request.getRequestURI()


3、文件的绝对路径 :application.getRealPath(request.getRequestURI());


4、当前web应用的绝对路径 :application.getRealPath("/");


5、取得请求文件的上层目录:newFile(application.getRealPath(request.getRequestURI())).getParent();



总结:

1、获取web服务器下的文件路径

request.getRealPath("/")

application.getRealPath("")【jsp中 】

ServletContext().getRealPath("")

System.getProperty("user.dir")【不同位置调用,获取的路径是动态变化的】


2、获取本地路径

jsp中,

request.getParameter("myFile");

ActionForm.getMyFile();

获取的值相同:如D:/VSS安装目录/users.txt

this.getClass().getClassLoader().getResource("").getPath();

==/D:/workspace/strutsTest/WebRoot/WEB-INF/classes/

this.getClass().getResource("").getPath().toString();

==/D:/workspace/strutsTest/WebRoot/WEB-INF/classes/bl/


3、获取相对路径

request.getContextPath();

如:/strutsTest


0 0
原创粉丝点击