1 利用ServletContext
http://reverocean.spaces.live.com/blog/cns!7174e1eea4de00ea!390.entryServlet中加载文件路径
1.给出相对路径(比如/WEB-INF/data.xml),通过ServletContext的getRealPath方法获取绝对路径
String path = context.getRealPath(pathname);
if(path != null){
return path;
}
if(path != null){
return path;
}
2.从ServletContext中获取应用服务器的临时目录:通过javax.servlet.context.tempdir
File dir = (File)context.getAttribute("javax.servlet.context.tempdir");
本文介绍了如何在Servlet中使用ServletContext来获取文件的真实路径,并通过ServletContext访问应用服务器的临时目录。同时,也概述了Spring框架中资源加载的支持方式。
3417

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



