Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing server port number in java file

 
naresh bv
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get the port number of a server dynamically.
For ex: If I use tomcat server then I will get port number as 8080
If I use WebLogic then that will be 7001, so on....
How can i get that port number in normal java file.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by naresh bv:
I want to get the port number of a server dynamically.
For ex: If I use tomcat server then I will get port number as 8080
If I use WebLogic then that will be 7001, so on....
How can i get that port number in normal java file.


I could not get the questions properly.

Well 8080 is the default port for Tomcat and can always be changed.

One more confusing thing is normal java file ?

Do you mean a standalone program making request to server.
In that case you can have a configuration file which will have port numbers and server type.Can you can change the program to read the port number and host name where the server is located from the configuration file and construct the request dynamically.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"naresh bv",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic