获取ServletContext:
如request.getSession(true).getServletContext()。
1: getContextPath() : String // 返回值: "/WebProjectName"。
2: getRealPath(String relativePath) : String // relativePath如/WEB-INF/***.txt, 返回文件在硬盘上的真实路径。
// 如要解析xml文件,则需要InputStream, relativePath如/WEB-INF/***.xml.
3: getResourceAsStream(String relativePath) : InputStream
本文深入探讨了如何从request中获取ServletContext,并详细解释了其关键方法如getContextPath()、getRealPath()和getResourceAsStream()的使用场景及作用。
784

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



