getServletContext().getResourceAsStream.示例如下:
InputStream is = getServletContext().getResourceAsStream("/WEB-INF/config.properties");
Properties props = new Properties();
try {
props.load(is);
} catch (IOException e) {
System.err.println("Load configuration failed");
}
PropertyConfigurator.configure(props);
上面方法并没有解决根本问题,根本问题就是得到RealPath,可以使用下面方法得到RealPath:
try {
URL u = getServletContext().getResource("/");
String weblogic_path=u.getPath();
} catch (MalformedURLException e) {
e.printStackTrace();
}
这个语句得到的RealPath可能不是最终的答案(一般来说前面多了一个/),需要你根据实际情况去加工一下。
至此问题全部解决。
解决weblogic中的getRealPath()问题
最新推荐文章于 2023-03-13 10:42:55 发布