JavaWeb项目在不同容器中正确获取项目路径
2014-03-20 22:31
323 查看
import java.io.File; import java.net.URLDecoder; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; public class InitServlet extends HttpServlet { @Override public void init() throws ServletException { String webpath=""; webpath = getServletConfig().getServletContext().getRealPath( ""); System.out.println("path1:========"+webpath); if(null==webpath || "".equals(webpath) || "null".equals(webpath)){ webpath=this.getClass().getClassLoader().getResource("/").getPath(); webpath=new File(webpath.substring(0,webpath.indexOf("WEB-INF"))).getPath(); } webpath=URLDecoder.decode(webpath+""); System.out.println("path2:========"+webpath); //D:\Program Files\apache-tomcat-6.0.35\webapps\Test } }
相关文章推荐
- javaweb项目中不同路径下的资源获取
- javaweb获取项目路径的方法
- javaweb获取项目路径的方法
- 获取WEB项目的不同路径的方法
- javaweb获取访问路径、域名、项目名、
- JavaWeb项目中各种路径的获取
- Wpf 获取项目根路径的正确方法
- Javaweb-获取项目路径
- JavaWeb的Filter中获取当前项目物理路径
- JavaWeb项目获取路径各种方法。
- JavaWeb项目各种路径的获取
- javaWeb项目下获取当前类的绝对路径
- C#获取项目程序路径的方法
- j2ee项目中在java类中获取,项目的绝对路径 spring框架的
- Android获取不同手机 自身存储和外置SD卡存储路径的解决方案
- eclipse rcp 获取工程项目路径
- javaweb项目中获取项目名称
- Java路径和java获取项目内文件
- C#获取项目程序路径的方法