tags:

views:

46

answers:

1

Is it possible to know in my Java code the port where a J2EE application has been deployed?

Is it possible to do a not container specific solution?

Thanks a lot in advance.

Edit: It whould be nice if this is discovered in a ServletContextListener since it will be done on startup.

+3  A: 

If you have a handle of the HttpServletRequest, then you can get it by ServletRequest#getServerPort() (the port which the client used) and/or ServletRequest#getLocalPort() (the port which the server actually uses --which might not be visible for the client due to router/proxy), depending on which port exactly you'd like to know about.

BalusC
The problem is that I need it for something that i'm doing on deployment time. If it was in a servlet that whould be a good idea.
Rafa de Castro
Oh, then you indeed have a problem. Either hardcode/configure it externally (not container specific), or make use of JMX (container specific though).
BalusC
Yup, in the end JMX had to be used.Thanks a lot
Rafa de Castro