code: private String getContextPath() {
      ClassLoader loader = getClass().getClassLoader();
      if(loader == null)
       return null;
      URL url = loader.getResource("/");
      if (url != null) {
        String[] elements = url.toString().split("/");
        for (int i = elements.length - 1; i > 0; --i) {
          // URLs look like this: file:/.../ImageServer/WEB-INF/classes/
          // And we want that part that's just before WEB-INF
          if ("WEB-INF".equals(elements[i])) {
            return elements[i - 1];
          }
        }
      }
      return null;
    }
docs: Tries to guess a context path for the running application.
  If this is a web application running under a tomcat server this will work.
  If unsuccessful, returns null.
  @return A string representing the current context path or null if it cannot be determined.