作为一个Java初级开发的学习者,最近学习了后台管理系统的开发。对于其中的一些问题做出总结。
第一:关于路径问题
1、获取web服务器下的文件路径
request.getRealPath("/")
application.getRealPath("")【jsp中 】
ServletContext().getRealPath("")
System.getProperty("user.dir")【不同位置调用,获取的路径是动态变化的】
2、获取本地路径
jsp中,<html:file property="myFile"/>
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();
另外:
在Java文件中getResource或getResourceAsStream均可
例:getClass().getResourceAsStream(filePath);//filePath可以是" /filename",这里的/代

最低0.47元/天 解锁文章
2610

被折叠的 条评论
为什么被折叠?



