Alfonso Tienda
Alfonso Tienda

Reputation: 3689

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.

Upvotes: 1

Views: 623

Answers (1)

user207421
user207421

Reputation: 310860

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.

Upvotes: 2

Related Questions