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");