Example #1
0
  /**
   * ��ȡWEB������·��
   *
   * @return
   */
  public static String getWebinfPath() {
    String strWebPath = "";

    String res = null;

    KeyFactory oTemp = new KeyFactory();
    String classname = oTemp.getClass().getName().replace('.', File.separatorChar) + ".class";

    ClassLoader oClassLoader = oTemp.getClass().getClassLoader();

    if (oClassLoader != null) {
      java.net.URL url = oClassLoader.getResource(classname);

      if (url != null) {
        String filePath = url.getFile();
        int fileStrPosition = filePath.indexOf("file:/");
        int begin = 0;
        int end = filePath.length();

        if (fileStrPosition >= 0) {
          begin = fileStrPosition + "file:".length();
        }

        // ���ж��Ƿ���δ����ļ�
        end = filePath.indexOf("classes/" + classname);
        if (end < 0) {
          // �������webModule�����jar��
          end = filePath.indexOf("lib/");
          if (end < 0) {
            // ����ͨĿ¼�µ�jar��
            int tmpend = filePath.indexOf("!/");

            if (tmpend >= 0) {
              end = filePath.substring(0, tmpend).lastIndexOf("/");
            }
          }
        }

        String rf = "";
        if (end < 0) {
          rf = filePath.substring(begin, filePath.length());
        } else {
          rf = filePath.substring(begin, end);
        }

        res = new File(rf).getAbsolutePath().replace('\\', '/') + "/";
      }
    }
    try {
      strWebPath = java.net.URLDecoder.decode(res, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
    }

    return strWebPath;
  }