Alfonso Tienda Alfonso Tienda - 15 days ago 5
Java Question

How can I get my local host and port in a Java servlet method init()?

How do I retrieve the port number in the init method.
In a

doGet
or
doPost
I can use:

request.getLocalPort();


but in the
init()
method there is no request object.

I don't want to configure it, I want the port dynamically.

EJP EJP
Answer

You can't. There is no such thing as 'the' port. The container could be listening on any number of ports and any number of IP addresses.