Announcement Announcement Module
No announcement yet.
Is there a way to get the Application URL from the ApplicationContext? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 :
    public class ContextInitListener implements ServletContextListener {
    	public void contextDestroyed(ServletContextEvent event) {
    	public void contextInitialized(ServletContextEvent event) {
    		ServletContext ctx = event.getServletContext();


    • #3
      What I mean by the application URL is something like:

      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 or, etc.

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