code: public static String resolveUrl(
              String url, String context, PageContext pageContext)
              throws JspException {
          // don't touch absolute URLs
          if (UrlUtil.isAbsoluteUrl(url)) {
              return url;
          }
  
          // normalize relative URLs against a context root
          HttpServletRequest request =
                  (HttpServletRequest) pageContext.getRequest();
          if (context == null) {
              if (url.startsWith("/")) {
                  return (request.getContextPath() + url);
              } else {
                  return url;
              }
          } else {
              if (!context.startsWith("/") || !url.startsWith("/")) {
                  throw new JspTagException(
                          Resources.getMessage("IMPORT_BAD_RELATIVE"));
              }
              if (context.endsWith("/") && url.startsWith("/")) {
                  // Don't produce string starting with '//', many
                  // browsers interpret this as host name, not as
                  // path on same host. Bug 22860
                  // Also avoid // inside the url. Bug 34109
                  return (context.substring(0, context.length() - 1) + url);
              } else {
                  return (context + url);
              }
          }
      }
docs: Utility methods