luinstein 发表于 2012-12-13 19:50:30

解决weblogic中的getRealPath()问题

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

from:http://blog.csdn.net/luinstein/article/details/5451371
页: [1]
查看完整版本: 解决weblogic中的getRealPath()问题