Announcement Announcement Module
Collapse
No announcement yet.
Is there a way to get the Application URL from the ApplicationContext? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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());
    	}
    }

    Comment


    • #3
      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.

      Comment

      Working...
      X