3 Replies Latest reply on Aug 3, 2005 12:01 PM by Scott Stark

    HOW-TO obtain URL for Web Application

    treespace Novice

      I frequently load URL based resources and I can get the URL using request attributes to generate a URL like this: https://acme:8443/portal

      The code is dirt simple:

      getURL( HTTPServletRequest r)
       return r.getScheme() + "://" + r.getServerName() + ":" +
       r.getServerPort() + r.getContextPath();

      The problem is I need that URL before a request is made and I do not want to hard-wire that. The ServletContext passed to Servlet.init() does not get me that information so I cannot use a load-on-start servlet, either.

      How can I get the scheme, host and port at startup? The context path is not an issue since obviously there can be several of those and I can hard wire that one.