获得WebRoot的物理路径

来源:互联网 发布:软件测试二八原则 编辑:程序博客网 时间:2024/05/18 02:38

spring框架的思路, 在WEB-INF/web.xml中 , 创建一个webAppRootKey的param, 指定一个值(默认为webapp.root)作为键值, 然后通过Listener , 或者Filter , 或者Servlet 执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root 分别作为Key , Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径.

web.xml

相应servlet

使用的代码:System.out.println(System.getProperty("webapp.root"));

原创粉丝点击