Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to get the URL basename and IP address of current serlet context?

843842Nov 13 2008 — edited Nov 14 2008
How to get the URL basename and IP address of current serlet context?

For example, if my website is "www.non-existent.website.com", and Tomcat is running on this website, then how can I get the website name? Preferrably I'd like to get it from the ServletContextEvent. What I want to do is this:
class MyListener implements ServletContextListener {
   public void contextInitialized(ServletContextEvent sce) {
      if (sce.getServletContext().getDomain().equals("www.non-existent.website.com"))
         setLoggerLevel(Level.WARN);
      else
         setLoggerLevel(Level.DEBUG);
   }
}
So when running the app server on a debug machine, I want to set the log level to DEBUG, otherwise to WARN. The DEBUG machine has the URL basename as "localhost".

Getting the IP address is a related question. But on a complex load balanced system, the IP address could change with each request.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 12 2008
Added on Nov 13 2008
3 comments
278 views