Results 1 to 3 of 3

Thread: Is there a way to get the Application URL from the ApplicationContext?

  1. #1
    Join Date
    Jan 2006
    Location
    Santa Fe, NM
    Posts
    5

    Default Is there a way to get the Application URL from the ApplicationContext?

    I would like to be able to get the URL on my web application from the ApplicationContext before any http requests have been made. I am able to get the URL from the HTTPRequest object, but will need the URL before any requests have come in.

    Is this possible?

  2. #2
    Join Date
    Oct 2008
    Location
    Delhi, India
    Posts
    163

    Default

    I assume you mean the context of the application when you say the "application URL". In that case you can use a ServletContextListener and get the context name.

    Something like this :
    Code:
    public class ContextInitListener implements ServletContextListener {
    
    	@Override
    	public void contextDestroyed(ServletContextEvent event) {
    
    	}
    
    	@Override
    	public void contextInitialized(ServletContextEvent event) {
    		ServletContext ctx = event.getServletContext();
                   System.out.println(ctx.getServletContextName());
    	}
    }

  3. #3
    Join Date
    Jan 2006
    Location
    Santa Fe, NM
    Posts
    5

    Default

    What I mean by the application URL is something like:

    http://www.deepwebtech.com/myapp

    I tried using the servletContext.getServletContextName(), which gives the application's Display Name, and that doesn't give me what I am looking for.

    I'm beginning to suspect that the application url is not available until the web server gets an http request. There could be multiple URLs that take you to the same resource, like http://localhost or http://231.233.22.11 or http://www.deepwebtech.com, etc.

    Thus, I may not be able to get the application URL until a request comes in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •