创星网络[分享知识 传递快乐]

标题: 解决weblogic中的getRealPath()问题 [打印本页]

作者: luinstein    时间: 2012-12-13 19:50
标题: 解决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(\"Load  configuration failed\");
            }
    PropertyConfigurator.configure(props);
  上面方法并没有解决根本问题,根本问题就是得到RealPath,可以使用下面方法得到RealPath:
           try {
             URL   u = getServletContext().getResource(\"/\");
            String  weblogic_path=u.getPath();
            } catch (MalformedURLException e) {
             e.printStackTrace();
             }
    这个语句得到的RealPath可能不是最终的答案(一般来说前面多了一个/),需要你根据实际情况去加工一下。
    至此问题全部解决。

from:http://blog.csdn.net/luinstein/article/details/5451371





欢迎光临 创星网络[分享知识 传递快乐] (http://bbs.cxweb.com.cn/) Powered by Discuz! X3