我使用網絡片段(servlet 3規範),因此可以加載例如通過ServletContext.getResourceAsStream(「access.xml」)在我的WAR的/ WEB-INF/lib /庫中的META-INF/resources/access.xml文件。ServletContext.getRealPath()是否適用於Web碎片?
對ServletContext.getRealPath(「access.xml」)執行相同操作無效(=> null)。
該規範規定:
The getRealPath method takes a String argument and returns a String representation of a file on the local file system to which a path corresponds. Resources inside the META-INF/resources directory of JAR file must be considered only if the container has unpacked them from their containing JAR file when a call to getRealPath() is made, and in this case MUST return the unpacked location.
我的容器(Tomcat)的沒有解開罐子,這似乎是這個問題? Tomcat如何解開罐子。打包WAR時,我應該拆開罐子嗎?